From a617a29e7518b4bdbf3788a207b4be4ebc49bc4d Mon Sep 17 00:00:00 2001 From: clement Date: Tue, 9 Jul 2024 19:49:50 +0200 Subject: [PATCH] Add view path list --- app/src/main/AndroidManifest.xml | 5 ++ .../busroute/{ => DataClass}/BusStop.kt | 3 +- .../example/busroute/DataClass/PathList.kt | 7 +++ .../java/com/example/busroute/MainActivity.kt | 43 +++------------- .../java/com/example/busroute/PathToMaps.kt | 49 +++++++++++++++++++ app/src/main/res/layout/main.xml | 9 ++++ app/src/main/res/layout/select_path.xml | 9 ++++ 7 files changed, 87 insertions(+), 38 deletions(-) rename app/src/main/java/com/example/busroute/{ => DataClass}/BusStop.kt (79%) create mode 100644 app/src/main/java/com/example/busroute/DataClass/PathList.kt create mode 100644 app/src/main/java/com/example/busroute/PathToMaps.kt create mode 100644 app/src/main/res/layout/select_path.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5b277da..75f7edd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,6 +31,11 @@ android:label="Ajouter une ligne" android:parentActivityName=".MainActivity" android:theme="@style/Theme.AppCompat"/> + \ No newline at end of file diff --git a/app/src/main/java/com/example/busroute/BusStop.kt b/app/src/main/java/com/example/busroute/DataClass/BusStop.kt similarity index 79% rename from app/src/main/java/com/example/busroute/BusStop.kt rename to app/src/main/java/com/example/busroute/DataClass/BusStop.kt index 42201d6..2e7a0ab 100644 --- a/app/src/main/java/com/example/busroute/BusStop.kt +++ b/app/src/main/java/com/example/busroute/DataClass/BusStop.kt @@ -1,7 +1,6 @@ -package com.example.busroute +package com.example.busroute.DataClass import org.osmdroid.views.overlay.Marker -import java.io.Serializable data class BusStop(val marker: Marker){ override fun toString(): String { diff --git a/app/src/main/java/com/example/busroute/DataClass/PathList.kt b/app/src/main/java/com/example/busroute/DataClass/PathList.kt new file mode 100644 index 0000000..8064e26 --- /dev/null +++ b/app/src/main/java/com/example/busroute/DataClass/PathList.kt @@ -0,0 +1,7 @@ +package com.example.busroute.DataClass + +data class PathList(val id: Int, val name: String){ + override fun toString(): String { + return name + } +} diff --git a/app/src/main/java/com/example/busroute/MainActivity.kt b/app/src/main/java/com/example/busroute/MainActivity.kt index 0c874b0..0e0e5fd 100644 --- a/app/src/main/java/com/example/busroute/MainActivity.kt +++ b/app/src/main/java/com/example/busroute/MainActivity.kt @@ -2,31 +2,24 @@ package com.example.busroute import android.annotation.SuppressLint import android.app.AlertDialog -import android.content.ContentValues import android.content.Context import android.content.Intent import android.content.pm.PackageManager -import android.location.Address -import android.location.Geocoder import android.location.Location import android.location.LocationManager import android.net.Uri import android.os.Bundle import android.preference.PreferenceManager -import android.provider.BaseColumns -import android.util.Log import android.view.WindowManager import android.widget.Button import android.widget.TextView import androidx.activity.ComponentActivity import androidx.core.app.ActivityCompat -import androidx.core.content.ContentProviderCompat.requireContext import androidx.core.content.ContextCompat +import com.example.busroute.DataClass.BusStop import com.example.busroute.Database.DbHelper -import com.example.busroute.Database.StopContract import com.google.android.gms.location.LocationCallback import com.google.android.gms.location.LocationRequest -import com.google.android.gms.location.LocationResult import org.osmdroid.api.IMapController import org.osmdroid.config.Configuration.getInstance import org.osmdroid.tileprovider.tilesource.TileSourceFactory @@ -39,7 +32,6 @@ import org.osmdroid.views.overlay.gestures.RotationGestureOverlay import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider import org.osmdroid.views.overlay.mylocation.IMyLocationProvider import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay -import java.util.Locale class MainActivity : ComponentActivity() { @@ -65,10 +57,6 @@ class MainActivity : ComponentActivity() { val dbHelper = DbHelper(this) isLocationPermissionGranted() - - - - locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this)) setContentView(R.layout.main) @@ -113,29 +101,6 @@ class MainActivity : ComponentActivity() { val intent = Intent(saveMarkButton.context, ValidateMarker::class.java) intent.putExtra(ValidateMarker.MARKERS, stringList) startActivity(intent) - - val dbread = dbHelper.readableDatabase - val projection = arrayOf(BaseColumns._ID, StopContract.StopEntry.LATITUDE, StopContract.StopEntry.LONGITUDE, StopContract.StopEntry.ORDER) - val selection = "" - val selectionArgs = arrayOf("") - val sortOrder = "${StopContract.StopEntry.ORDER} ASC" - val cursor = dbread.query( - StopContract.StopEntry.TABLE_NAME, // The table to query - projection, // The array of columns to return (pass null to get all) - null, // The columns for the WHERE clause - null, // The values for the WHERE clause - null, // don't group the rows - null, // don't filter by row groups - sortOrder // The sort order - ) - val itemIds = mutableListOf() - with(cursor) { - while (moveToNext()) { - val item = getString(getColumnIndexOrThrow(StopContract.StopEntry.LATITUDE))+getString(getColumnIndexOrThrow(StopContract.StopEntry.LONGITUDE)) - //itemIds.add(itemId) - } - } - cursor.close() } @@ -148,6 +113,12 @@ class MainActivity : ComponentActivity() { startActivity(mapIntent) } + val loadPathButton = findViewById