Add select path in main activity
This commit is contained in:
11
.idea/other.xml
generated
11
.idea/other.xml
generated
@@ -179,17 +179,6 @@
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2400" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="31" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="q2q" />
|
||||
<option name="id" value="q2q" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Z Fold3" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1768" />
|
||||
<option name="screenY" value="2208" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.example.busroute.DataClass
|
||||
|
||||
import com.example.busroute.Database.PathContract
|
||||
import com.example.busroute.Database.StopContract
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
|
||||
data class ExportPath(val pathName:String, val busStop:ArrayList<Stop>){
|
||||
fun getJson():JsonObject{
|
||||
val path = JsonObject()
|
||||
path.addProperty(PathContract.PathEntry.PATH_NAME, pathName)
|
||||
val stopList = JsonArray()
|
||||
busStop.forEach {
|
||||
val stop = JsonObject()
|
||||
stop.addProperty(StopContract.StopEntry.LATITUDE, it.latitude)
|
||||
stop.addProperty(StopContract.StopEntry.LONGITUDE, it.longitude)
|
||||
stop.addProperty(StopContract.StopEntry.ORDER, it.order)
|
||||
stopList.add(stop)
|
||||
}
|
||||
path.add("stop", stopList)
|
||||
return path
|
||||
}
|
||||
}
|
||||
3
app/src/main/java/com/example/busroute/DataClass/Stop.kt
Normal file
3
app/src/main/java/com/example/busroute/DataClass/Stop.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
package com.example.busroute.DataClass
|
||||
|
||||
data class Stop(val latitude:Double, val longitude:Double, val order:Int)
|
||||
@@ -6,22 +6,28 @@ import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.SensorListener
|
||||
import android.hardware.SensorManager
|
||||
import android.location.Location
|
||||
import android.location.LocationManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.speech.tts.TextToSpeech
|
||||
import android.speech.tts.Voice
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.AdapterView
|
||||
import android.widget.AdapterView.OnItemSelectedListener
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Button
|
||||
import android.widget.Spinner
|
||||
import android.widget.TextView
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.example.busroute.DataClass.BusStop
|
||||
import com.example.busroute.DataClass.PathList
|
||||
import com.example.busroute.Database.DbHelper
|
||||
import com.example.busroute.Database.PathContract
|
||||
import com.google.android.gms.location.LocationCallback
|
||||
import com.google.android.gms.location.LocationRequest
|
||||
import org.osmdroid.api.IMapController
|
||||
@@ -30,14 +36,11 @@ import org.osmdroid.tileprovider.tilesource.TileSourceFactory
|
||||
import org.osmdroid.util.GeoPoint
|
||||
import org.osmdroid.views.MapView
|
||||
import org.osmdroid.views.overlay.Marker
|
||||
import org.osmdroid.views.overlay.compass.CompassOverlay
|
||||
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider
|
||||
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
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
@@ -81,6 +84,10 @@ class MainActivity : ComponentActivity() {
|
||||
mapController = map.controller
|
||||
mapController.setZoom(18.0)
|
||||
|
||||
val openMapsButton = findViewById<Button>(R.id.open_maps)
|
||||
|
||||
val db = dbHelper.readableDatabase
|
||||
|
||||
val addMarkButton = findViewById<Button>(R.id.addMark)
|
||||
addMarkButton.setOnClickListener{
|
||||
val marker = Marker(map)
|
||||
@@ -117,11 +124,11 @@ class MainActivity : ComponentActivity() {
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
val loadPathButton = findViewById<Button>(R.id.load_path)
|
||||
loadPathButton.setOnClickListener {
|
||||
val intent = Intent(loadPathButton.context, PathToMaps::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
// val loadPathButton = findViewById<Button>(R.id.load_path)
|
||||
// loadPathButton.setOnClickListener {
|
||||
// val intent = Intent(loadPathButton.context, PathToMaps::class.java)
|
||||
// startActivity(intent)
|
||||
// }
|
||||
|
||||
|
||||
val rotationGestureOverlay = RotationGestureOverlay(map)
|
||||
@@ -150,10 +157,8 @@ class MainActivity : ComponentActivity() {
|
||||
mapController.animateTo(GeoPoint(latitude, longitude), null, null, -currentLocation.bearing)
|
||||
}
|
||||
else{
|
||||
mapController.animateTo(GeoPoint(latitude, longitude))
|
||||
//mapController.animateTo(GeoPoint(latitude, longitude))
|
||||
}
|
||||
|
||||
findViewById<TextView>(R.id.accuracy).text = "${location.accuracy} %"
|
||||
}
|
||||
}
|
||||
locationOverlay.enableMyLocation()
|
||||
@@ -167,44 +172,98 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
|
||||
// val locationClient = LocationServices.getFusedLocationProviderClient(this)
|
||||
//
|
||||
// locationRequest = LocationRequest.Builder(Priority.PRIORITY_BALANCED_POWER_ACCURACY,60)
|
||||
// .setWaitForAccurateLocation(true).setMaxUpdateAgeMillis(30).build()
|
||||
// locationCallback = object : LocationCallback() {
|
||||
// @SuppressLint("SetTextI18n")
|
||||
// override fun onLocationResult(locationResult: LocationResult) {
|
||||
// locationResult ?: return
|
||||
// for (location in locationResult.locations){
|
||||
// if(location.accuracy < 60){
|
||||
// if(location.provider == LocationManager.NETWORK_PROVIDER){
|
||||
// location.provider = LocationManager.GPS_PROVIDER
|
||||
// }else{
|
||||
// location.provider = LocationManager.NETWORK_PROVIDER
|
||||
// }
|
||||
// }
|
||||
// currentLocation = location
|
||||
// latitude = location.latitude
|
||||
// longitude = location.longitude
|
||||
// mapController.animateTo(GeoPoint(latitude, longitude))
|
||||
//
|
||||
// positionMarker.position = GeoPoint(latitude, longitude)
|
||||
// positionMarker.title = "You"
|
||||
// map.overlays.add(positionMarker)
|
||||
// map.invalidate()
|
||||
//
|
||||
// findViewById<TextView>(R.id.accuracy).text = "${location.accuracy} %"
|
||||
// findViewById<TextView>(R.id.position).text = "$latitude $longitude"
|
||||
// findViewById<TextView>(R.id.speed).text = "${location.speed} m/s"
|
||||
// findViewById<TextView>(R.id.speed_accuracy).text = "${location.speedAccuracyMetersPerSecond} %"
|
||||
//
|
||||
// Log.i("Position", "$latitude $longitude")
|
||||
// Log.i("Accuracy Chosen", "${location.accuracy}")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// locationClient.requestLocationUpdates(locationRequest, locationCallback, Looper.getMainLooper())
|
||||
|
||||
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>()
|
||||
items.add(PathList(0,"SELECT PATH"))
|
||||
with(cursor) {
|
||||
while (moveToNext()) {
|
||||
val name = getString(getColumnIndexOrThrow(com.example.busroute.Database.PathContract.PathEntry.PATH_NAME))
|
||||
val id = getInt(getColumnIndexOrThrow(android.provider.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)
|
||||
comboPath.onItemSelectedListener = object : OnItemSelectedListener {
|
||||
override fun onItemSelected(
|
||||
parentView: AdapterView<*>?,
|
||||
selectedItemView: View,
|
||||
position: Int,
|
||||
id: Long
|
||||
) {
|
||||
val iter = busStopList.iterator()
|
||||
while(iter.hasNext()) {
|
||||
iter.next().marker.remove(map)
|
||||
iter.remove()
|
||||
}
|
||||
if(position < 1){
|
||||
addMarkButton.isEnabled = true
|
||||
return
|
||||
}
|
||||
addMarkButton.isEnabled = false
|
||||
val selectedPath = parentView!!.selectedItem
|
||||
if(selectedPath != null){
|
||||
val cursor = db.rawQuery("SELECT * " +
|
||||
"FROM stop " +
|
||||
"WHERE path_id = ${(selectedPath as PathList).id} " +
|
||||
"ORDER BY 'order' ",
|
||||
arrayOf()
|
||||
)
|
||||
with(cursor) {
|
||||
while (moveToNext()) {
|
||||
val latitude = getDouble(getColumnIndexOrThrow(com.example.busroute.Database.StopContract.StopEntry.LATITUDE))
|
||||
val longitude = getDouble(getColumnIndexOrThrow(com.example.busroute.Database.StopContract.StopEntry.LONGITUDE))
|
||||
val text = TextView(comboPath.context)
|
||||
val marker = Marker(map)
|
||||
marker.position = GeoPoint(latitude, longitude)
|
||||
marker.title = "Bus Stop " + busStopList.size+1
|
||||
marker.textLabelFontSize = 10
|
||||
marker.icon = ContextCompat.getDrawable(baseContext, org.osmdroid.library.R.drawable.moreinfo_arrow)
|
||||
map.overlays.add(marker)
|
||||
map.invalidate()
|
||||
busStopList.add(BusStop(marker))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parentView: AdapterView<*>?) {
|
||||
// your code here
|
||||
}
|
||||
}
|
||||
openMapsButton.setOnClickListener {
|
||||
val lastPoint = busStopList.last().marker
|
||||
var uri = "google.navigation:q=${lastPoint.position.latitude},${lastPoint.position.longitude}&waypoints="
|
||||
busStopList.forEach {
|
||||
if(busStopList.indexOf(it) < busStopList.size -1){
|
||||
val position = it.marker.position
|
||||
uri += "${position.latitude},${position.longitude}"
|
||||
if(busStopList.indexOf(it) < busStopList.size -2){
|
||||
uri += "%7C"
|
||||
}
|
||||
}
|
||||
}
|
||||
db.close()
|
||||
val mapIntentUri = Uri.parse(uri)
|
||||
val mapIntent = Intent(Intent.ACTION_VIEW, mapIntentUri)
|
||||
mapIntent.setPackage("com.google.android.apps.maps")
|
||||
startActivity(mapIntent)
|
||||
}
|
||||
}
|
||||
private fun isLocationPermissionGranted(): Boolean {
|
||||
return if (ActivityCompat.checkSelfPermission(
|
||||
|
||||
@@ -15,10 +15,13 @@ import android.widget.Spinner
|
||||
import android.widget.TableLayout
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.busroute.DataClass.ExportPath
|
||||
import com.example.busroute.DataClass.PathList
|
||||
import com.example.busroute.DataClass.Stop
|
||||
import com.example.busroute.Database.DbHelper
|
||||
import com.example.busroute.Database.PathContract
|
||||
import com.example.busroute.Database.StopContract
|
||||
import com.google.gson.JsonArray
|
||||
import java.util.Locale
|
||||
|
||||
|
||||
@@ -95,7 +98,6 @@ class PathToMaps: AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val openMapsButton = findViewById<Button>(R.id.open_maps)
|
||||
openMapsButton.setOnClickListener {
|
||||
val lastPoint = StopPoint.last().split("|")
|
||||
@@ -115,5 +117,27 @@ class PathToMaps: AppCompatActivity() {
|
||||
mapIntent.setPackage("com.google.android.apps.maps")
|
||||
startActivity(mapIntent)
|
||||
}
|
||||
val exportJsonButton = findViewById<Button>(R.id.export_json)
|
||||
exportJsonButton.setOnClickListener {
|
||||
val exportList = JsonArray()
|
||||
val busStopList = ArrayList<Stop>()
|
||||
items.forEach {
|
||||
val cursor = db.rawQuery("SELECT * " +
|
||||
"FROM stop " +
|
||||
"WHERE path_id = ${it.id} " +
|
||||
"ORDER BY 'order' ",
|
||||
arrayOf()
|
||||
)
|
||||
with(cursor) {
|
||||
while (moveToNext()) {
|
||||
val latitude = getDouble(getColumnIndexOrThrow(StopContract.StopEntry.LATITUDE))
|
||||
val longitude = getDouble(getColumnIndexOrThrow(StopContract.StopEntry.LONGITUDE))
|
||||
val order = getInt(getColumnIndexOrThrow("order"))
|
||||
busStopList.add(Stop(latitude, longitude, order))
|
||||
}
|
||||
}
|
||||
exportList.add(ExportPath(it.name, busStopList).getJson())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,17 @@
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<RelativeLayout tools:ignore="UselessParent">
|
||||
<TableLayout
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@color/white"
|
||||
android:elevation="600dp">
|
||||
<Spinner
|
||||
android:id="@+id/combo_path"
|
||||
android:background="@color/white"
|
||||
android:layout_height="35dp">
|
||||
</Spinner>
|
||||
</TableLayout>
|
||||
<TableLayout
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -40,14 +51,14 @@
|
||||
android:clickable="true"
|
||||
android:text="Save Markers" />
|
||||
<Button
|
||||
android:id="@+id/load_path"
|
||||
android:id="@+id/open_maps"
|
||||
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" />
|
||||
android:text="Lancer le trajet dans Maps">
|
||||
</Button>
|
||||
<Button
|
||||
android:id="@+id/road"
|
||||
android:layout_width="150dp"
|
||||
@@ -57,21 +68,11 @@
|
||||
android:textColor="@color/black"
|
||||
android:clickable="true"
|
||||
android:text="Test Road Manager" />
|
||||
<TextView
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black"
|
||||
android:text="Accuracy"/>
|
||||
<TextView
|
||||
android:id="@+id/accuracy"
|
||||
android:layout_width="150dp"
|
||||
android:textColor="@color/black"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""/>
|
||||
|
||||
</TableLayout>
|
||||
<org.osmdroid.views.MapView
|
||||
android:id="@+id/map"
|
||||
android:elevation="0dp"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
android:id="@+id/open_maps"
|
||||
android:text="Lancer le trajet dans Maps">
|
||||
|
||||
</Button>
|
||||
<Button
|
||||
android:id="@+id/export_json"
|
||||
android:text="Exporter tous les trajets">
|
||||
|
||||
</Button>
|
||||
<TableLayout
|
||||
android:id="@+id/stop_table"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[versions]
|
||||
agp = "8.5.0"
|
||||
commonsLang3 = "3.8.1"
|
||||
gson = "2.10.1"
|
||||
gson = "2.11.0"
|
||||
kotlin = "1.9.0"
|
||||
coreKtx = "1.13.1"
|
||||
junit = "4.13.2"
|
||||
@@ -18,13 +18,13 @@ appcompat = "1.7.0"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commonsLang3" }
|
||||
commons-lang3 = { module = "org.apache.commons:commons-lang3", version = "3.16.0" }
|
||||
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
|
||||
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
|
||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version = "1.2.1" }
|
||||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version = "3.6.1" }
|
||||
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version = "2.8.4" }
|
||||
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version = "1.9.1" }
|
||||
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
|
||||
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
|
||||
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
|
||||
@@ -33,7 +33,7 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
|
||||
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
|
||||
okhttp = { module = "com.squareup.okhttp3:okhttp", version = "4.12.0" }
|
||||
osmbonuspack = { module = "com.github.MKergall:osmbonuspack", version.ref = "osmbonuspack" }
|
||||
osmdroid-android = { module = "org.osmdroid:osmdroid-android", version.ref = "osmdroidAndroid" }
|
||||
play-services-location = { group = "com.google.android.gms", name = "play-services-location", version.ref = "playServicesLocation" }
|
||||
|
||||
Reference in New Issue
Block a user