Search in sources :

Example 1 with Station

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;
}
Also used : 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) Timetable(de.bahnhoefe.deutschlands.bahnhofsfotos.util.Timetable) SimpleDialogs(de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs) Intent(android.content.Intent) ProviderApp(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ProviderApp) Point(android.graphics.Point)

Example 2 with Station

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();
}
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)

Example 3 with Station

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();
}
Also used : Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station) LatLong(org.mapsforge.core.model.LatLong)

Example 4 with Station

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);
    }
}
Also used : Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station) Intent(android.content.Intent)

Example 5 with Station

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);
    }
}
Also used : Station(de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station)

Aggregations

Station (de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station)5 Intent (android.content.Intent)3 ValueAnimator (android.animation.ValueAnimator)2 ActionBar (android.app.ActionBar)2 Activity (android.app.Activity)2 TaskStackBuilder (android.app.TaskStackBuilder)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ComponentName (android.content.ComponentName)2 Context (android.content.Context)2 Intent.createChooser (android.content.Intent.createChooser)2 PackageManager (android.content.pm.PackageManager)2 Bitmap (android.graphics.Bitmap)2 BitmapFactory (android.graphics.BitmapFactory)2 Color (android.graphics.Color)2 WHITE (android.graphics.Color.WHITE)2 Point (android.graphics.Point)2 PorterDuff (android.graphics.PorterDuff)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 ParcelFileDescriptor (android.os.ParcelFileDescriptor)2