Add view path list

This commit is contained in:
clement
2024-07-09 19:49:50 +02:00
parent e096f9ed1c
commit a617a29e75
7 changed files with 87 additions and 38 deletions

View File

@@ -31,6 +31,11 @@
android:label="Ajouter une ligne"
android:parentActivityName=".MainActivity"
android:theme="@style/Theme.AppCompat"/>
<activity
android:name=".PathToMaps"
android:label="Charger un trajet"
android:parentActivityName=".MainActivity"
android:theme="@style/Theme.AppCompat"/>
</application>
</manifest>

View File

@@ -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 {

View File

@@ -0,0 +1,7 @@
package com.example.busroute.DataClass
data class PathList(val id: Int, val name: String){
override fun toString(): String {
return name
}
}

View File

@@ -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<Long>()
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<Button>(R.id.load_path)
loadPathButton.setOnClickListener {
val intent = Intent(loadPathButton.context, PathToMaps::class.java)
startActivity(intent)
}
val rotationGestureOverlay = RotationGestureOverlay(map)
rotationGestureOverlay.isEnabled
map.setMultiTouchControls(true)

View File

@@ -0,0 +1,49 @@
package com.example.busroute
import android.os.Bundle
import android.provider.BaseColumns
import android.widget.ArrayAdapter
import android.widget.Spinner
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.menu.MenuBuilder.ItemInvoker
import com.example.busroute.DataClass.PathList
import com.example.busroute.Database.DbHelper
import com.example.busroute.Database.PathContract
class PathToMaps: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val dbHelper = DbHelper(this)
val db = dbHelper.readableDatabase
setContentView(R.layout.select_path)
val projection = arrayOf("")
val selection = ""
val selectionArgs = arrayOf("")
val sortOrder = ""
val cursor = db.query(
PathContract.PathEntry.TABLE_NAME, // The table to query
null, // 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
null // The sort order
)
val items = ArrayList<PathList>()
with(cursor) {
while (moveToNext()) {
val name = getString(getColumnIndexOrThrow(PathContract.PathEntry.PATH_NAME))
val id = getInt(getColumnIndexOrThrow(BaseColumns._ID))
val path = PathList(id, name)
items.add(path)
}
}
cursor.close()
val comboPath = findViewById<Spinner>(R.id.combo_path)
comboPath.adapter = ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item, items)
}
}

View File

@@ -48,6 +48,15 @@
android:textColor="@color/black"
android:clickable="true"
android:text="Test Google Maps" />
<Button
android:id="@+id/load_path"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:focusable="true"
android:textColor="@color/black"
android:clickable="true"
android:text="Load path" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="@+id/combo_path">
</Spinner>
</TableLayout>