// Path: app/src/main/java/net/fabiszewski/ulogger/Alert.java
// static AlertDialog showAlert(Activity context, CharSequence title, int layoutResource, int iconResource) {
//     @SuppressLint("InflateParams")
//     View view = context.getLayoutInflater().inflate(layoutResource, null, false);
//     AlertDialog alertDialog = new AlertDialog.Builder(context).create();
//     alertDialog.setTitle(title);
//     alertDialog.setView(view);
//     if (iconResource > 0) {
//         alertDialog.setIcon(iconResource);
//     }
//     alertDialog.show();
//     return alertDialog;
// }
// 
// Path: app/src/main/java/net/fabiszewski/ulogger/Alert.java
// static void showConfirm(Context context, CharSequence title, CharSequence message,
//                                DialogInterface.OnClickListener yesCallback) {
//     AlertDialog alertDialog = initDialog(context, title, message);
//     alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.ok), yesCallback);
//     alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(R.string.cancel),
//             (dialog, which) -> dialog.dismiss());
//     alertDialog.show();
// }
// 
// Path: app/src/main/java/net/fabiszewski/ulogger/GpxExportTask.java
// public static final String GPX_EXTENSION = ".gpx";


import static androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
import static net.fabiszewski.ulogger.Alert.showAlert;
import static net.fabiszewski.ulogger.Alert.showConfirm;
import static net.fabiszewski.ulogger.GpxExportTask.GPX_EXTENSION;
import static java.util.concurrent.Executors.newCachedThreadPool;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.preference.PreferenceManager;
import java.util.concurrent.ExecutorService;

    /**
     * Display warning if track name is not set
     */
    public void showNoTrackWarning() {
        showToast(getString(R.string.no_track_warning));
    }

    /**
     * Start export service
     */
    private void startExport() {
        if (db.countPositions() > 0) {
            try {
                getExportUri.launch(DbAccess.getTrackName(this) + GPX_EXTENSION);
            } catch (ActivityNotFoundException e) {
                showToast(getString(R.string.cannot_open_picker), Toast.LENGTH_LONG);
            }
        } else {
            showToast(getString(R.string.nothing_to_export));
        }
    }


    private void clearTrack() {
        if (LoggerService.isRunning()) {
            showToast(getString(R.string.logger_running_warning));
            return;
        }
        if (DbAccess.getTrackName(MainActivity.this) != null) {
// Path: app/src/main/java/net/fabiszewski/ulogger/Alert.java
// static AlertDialog showAlert(Activity context, CharSequence title, int layoutResource, int iconResource) {
//     @SuppressLint("InflateParams")
//     View view = context.getLayoutInflater().inflate(layoutResource, null, false);
//     AlertDialog alertDialog = new AlertDialog.Builder(context).create();
//     alertDialog.setTitle(title);
//     alertDialog.setView(view);
//     if (iconResource > 0) {
//         alertDialog.setIcon(iconResource);
//     }
//     alertDialog.show();
//     return alertDialog;
// }
// 
// Path: app/src/main/java/net/fabiszewski/ulogger/Alert.java
// static void showConfirm(Context context, CharSequence title, CharSequence message,
//                                DialogInterface.OnClickListener yesCallback) {
//     AlertDialog alertDialog = initDialog(context, title, message);
//     alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.ok), yesCallback);
//     alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(R.string.cancel),
//             (dialog, which) -> dialog.dismiss());
//     alertDialog.show();
// }
// 
// Path: app/src/main/java/net/fabiszewski/ulogger/GpxExportTask.java
// public static final String GPX_EXTENSION = ".gpx";


// Path: app/src/main/java/net/fabiszewski/ulogger/MainActivity.java
import static androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
import static net.fabiszewski.ulogger.Alert.showAlert;
import static net.fabiszewski.ulogger.Alert.showConfirm;
import static net.fabiszewski.ulogger.GpxExportTask.GPX_EXTENSION;
import static java.util.concurrent.Executors.newCachedThreadPool;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.preference.PreferenceManager;
import java.util.concurrent.ExecutorService;


    /**
     * Display warning if track name is not set
     */
    public void showNoTrackWarning() {
        showToast(getString(R.string.no_track_warning));
    }

    /**
     * Start export service
     */
    private void startExport() {
        if (db.countPositions() > 0) {
            try {
                getExportUri.launch(DbAccess.getTrackName(this) + GPX_EXTENSION);
            } catch (ActivityNotFoundException e) {
                showToast(getString(R.string.cannot_open_picker), Toast.LENGTH_LONG);
            }
        } else {
            showToast(getString(R.string.nothing_to_export));
        }
    }


    private void clearTrack() {
        if (LoggerService.isRunning()) {
            showToast(getString(R.string.logger_running_warning));
            return;
        }
        if (DbAccess.getTrackName(MainActivity.this) != null) {
            showConfirm(MainActivity.this,