Search in sources :

Example 1 with NavItem

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();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ImageButton(android.widget.ImageButton) Timetable(de.bahnhoefe.deutschlands.bahnhofsfotos.util.Timetable) CheckedInputStream(java.util.zip.CheckedInputStream) Bundle(android.os.Bundle) ParcelFileDescriptor(android.os.ParcelFileDescriptor) ActivityDetailsBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ActivityDetailsBinding) PackageManager(android.content.pm.PackageManager) InboxResponse(de.bahnhoefe.deutschlands.bahnhofsfotos.model.InboxResponse) ProblemType(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ProblemType) NonNull(androidx.annotation.NonNull) BitmapCache(de.bahnhoefe.deutschlands.bahnhofsfotos.util.BitmapCache) Uri(android.net.Uri) LinkMovementMethod(android.text.method.LinkMovementMethod) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) StringUtils(org.apache.commons.lang3.StringUtils) ConnectionUtil(de.bahnhoefe.deutschlands.bahnhofsfotos.util.ConnectionUtil) Gson(com.google.gson.Gson) Locale(java.util.Locale) MediaStore(android.provider.MediaStore) ContextThemeWrapper(android.view.ContextThemeWrapper) View(android.view.View) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) MediaType(okhttp3.MediaType) Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station) NavUtils(androidx.core.app.NavUtils) DbAdapter(de.bahnhoefe.deutschlands.bahnhofsfotos.db.DbAdapter) ProviderApp(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ProviderApp) Set(java.util.Set) StationInfoBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.StationInfoBinding) UploadBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.UploadBinding) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ListAdapter(android.widget.ListAdapter) RSAPIClient(de.bahnhoefe.deutschlands.bahnhofsfotos.rsapi.RSAPIClient) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) FileProvider(androidx.core.content.FileProvider) Constants(de.bahnhoefe.deutschlands.bahnhofsfotos.util.Constants) EditorInfo(android.view.inputmethod.EditorInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Call(retrofit2.Call) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) FileUtils(de.bahnhoefe.deutschlands.bahnhofsfotos.util.FileUtils) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) ProblemReport(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ProblemReport) KeyValueSpinnerItem(de.bahnhoefe.deutschlands.bahnhofsfotos.util.KeyValueSpinnerItem) Response(retrofit2.Response) Intent.createChooser(android.content.Intent.createChooser) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) RequestBody(okhttp3.RequestBody) InboxStateQuery(de.bahnhoefe.deutschlands.bahnhofsfotos.model.InboxStateQuery) Country(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Country) URLConnection(java.net.URLConnection) Toast(android.widget.Toast) Menu(android.view.Menu) BitmapAvailableHandler(de.bahnhoefe.deutschlands.bahnhofsfotos.util.BitmapAvailableHandler) ActionBar(android.app.ActionBar) TaskStackBuilder(android.app.TaskStackBuilder) NavItem(de.bahnhoefe.deutschlands.bahnhofsfotos.util.NavItem) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) ComponentName(android.content.ComponentName) ActivityCompat(androidx.core.app.ActivityCompat) FileOutputStream(java.io.FileOutputStream) Point(android.graphics.Point) TextUtils(android.text.TextUtils) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) WHITE(android.graphics.Color.WHITE) File(java.io.File) Color(android.graphics.Color) ArrayAdapter(android.widget.ArrayAdapter) URLEncoder(java.net.URLEncoder) Callback(retrofit2.Callback) ReportProblemBinding(de.bahnhoefe.deutschlands.bahnhofsfotos.databinding.ReportProblemBinding) Bitmap(android.graphics.Bitmap) Upload(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) CRC32(java.util.zip.CRC32) Activity(android.app.Activity) ValueAnimator(android.animation.ValueAnimator) ViewGroup(android.view.ViewGroup) TaskStackBuilder(android.app.TaskStackBuilder) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) Point(android.graphics.Point) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Toast(android.widget.Toast) NonNull(androidx.annotation.NonNull) TextView(android.widget.TextView) NavItem(de.bahnhoefe.deutschlands.bahnhofsfotos.util.NavItem) ListAdapter(android.widget.ListAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

ValueAnimator (android.animation.ValueAnimator)1 ActionBar (android.app.ActionBar)1 Activity (android.app.Activity)1 TaskStackBuilder (android.app.TaskStackBuilder)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Intent.createChooser (android.content.Intent.createChooser)1 PackageManager (android.content.pm.PackageManager)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Color (android.graphics.Color)1 WHITE (android.graphics.Color.WHITE)1 Point (android.graphics.Point)1 PorterDuff (android.graphics.PorterDuff)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 MediaStore (android.provider.MediaStore)1