Skip to content
Snippets Groups Projects
Commit a0fb7780 authored by julien.debray's avatar julien.debray
Browse files

done

parent 87123410
No related branches found
No related tags found
No related merge requests found
Showing
with 9 additions and 191 deletions
No preview for this file type
......@@ -6,12 +6,12 @@ plugins {
android {
namespace 'com.example.mushroomstracker'
compileSdk 33
compileSdk 32
defaultConfig {
applicationId "com.example.mushroomstracker"
minSdk 29
targetSdk 33
targetSdk 32
versionCode 1
versionName "1.0"
......@@ -44,6 +44,6 @@ dependencies {
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.google.maps.android:android-maps-utils:2.2.3'
implementation 'com.google.maps.android:maps-utils-ktx:3.2.0'
implementation 'androidx.sqlite:sqlite-ktx:2.3.0'
implementation 'com.google.android.material:material:1.4.0'
}
\ No newline at end of file
......@@ -16,7 +16,9 @@
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity"
<activity
android:name=".MapsActivity"
android:theme="@style/SplashTheme"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......@@ -24,11 +26,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapsActivity"
android:theme="@style/SplashTheme"
android:exported="true">
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
......
package com.example.mushroomstracker
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
class DatabaseHelper(context: Context) : SQLiteOpenHelper(context, "database.db", null, 1) {
override fun onCreate(db: SQLiteDatabase?) {
val cueilletteTable = "CREATE TABLE CUEILLETTE(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, COMMENTAIRE TEXT);"
db?.execSQL(cueilletteTable)
val parcoursTable = "CREATE TABLE PARCOURS(LONGITUDE REAL NOT NULL, LATITUDE REAL NOT NULL, ID_CUEILLETTE INTEGER NOT NULL, FOREIGN KEY (ID_CUEILLETTE) REFERENCES CUEILLETTE(ID));"
db?.execSQL(parcoursTable)
val mushroomTable = "CREATE TABLE CHAMPIGNON(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, DESCRIPTION TEXT, DATE TEXT NOT NULL, QUANTITY INTEGER NOT NULL, IMAGE TEXT, LONGITUDE REAL NOT NULL, LATITUDE REAL NOT NULL, ID_CUEILLETTE INTEGER NOT NULL, FOREIGN KEY (ID_CUEILLETTE) REFERENCES CUEILLETTE(ID));"
db?.execSQL(mushroomTable)
}
override fun onUpgrade(db: SQLiteDatabase?, p1: Int, p2: Int) {
db?.execSQL("DROP TABLE IF EXISTS CHAMPIGNON")
db?.execSQL("DROP TABLE IF EXISTS PARCOURS")
db?.execSQL("DROP TABLE IF EXISTS CUEILLETTE")
if (db != null) {
onCreate(db)
}
}
}
\ No newline at end of file
package com.example.mushroomstracker
import MyAdapter
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button = findViewById<Button>(R.id.button_new_picking)
button.setOnClickListener {
Toast.makeText(this, "je clique", Toast.LENGTH_LONG)
val intent = Intent(this, MapsActivity::class.java)
startActivity(intent)
}
val data = listOf("Item 1", "Item 2", "Item 3")
val recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = MyAdapter(data)
}
}
\ No newline at end of file
package com.example.mushroomstracker
import android.Manifest
import android.annotation.SuppressLint
import android.content.ContentValues
import android.content.Context
import android.content.pm.PackageManager
import android.location.Location
import android.location.LocationManager
import android.os.Bundle
import android.os.SystemClock
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import com.example.mushroomstracker.databinding.ActivityMapsBinding
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
......@@ -23,7 +16,6 @@ import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.gms.maps.model.PolylineOptions
import java.time.LocalDate
class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarkerClickListener {
private lateinit var map: GoogleMap
......@@ -96,7 +88,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
map.addPolyline(polylineOptions)
}
@SuppressLint("InflateParams", "ServiceCast")
@SuppressLint("InflateParams")
private fun placeMarkerOnMap(location: LatLng){
Toast.makeText(this, "HELP", Toast.LENGTH_SHORT).show()
val builder = AlertDialog.Builder(this)
......@@ -105,25 +97,6 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
val dialogLayout = inflater.inflate(R.layout.new_marker, null)
builder.setView(dialogLayout)
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_FINE_LOCATION
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(
this,
Manifest.permission.ACCESS_COARSE_LOCATION
) != PackageManager.PERMISSION_GRANTED
) {
// Demande les autorisations si elles ne sont pas accordées
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
1
)
return
}
val db = DatabaseHelper(this).writableDatabase
val title = dialogLayout.findViewById<EditText>(R.id.markerTitleEditText)
val description = dialogLayout.findViewById<EditText>(R.id.markerDescriptionEditText)
val quantity = dialogLayout.findViewById<EditText>(R.id.markerQuantiteEditText)
......@@ -133,23 +106,6 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarker
marker.title(title.text.toString())
marker.snippet("Description : " + description.text.toString() + "\n" + "Quantité : " + quantity.text.toString())
map.addMarker(marker)
val content = ContentValues()
content.put("name", title.text.toString())
content.put("description", description.text.toString())
content.put("quantity", quantity.text.toString().toInt())
content.put("date", LocalDate.now().toString())
val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
val location: Location? = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
println(location?.longitude)
println(location?.latitude)
if (location != null) {
content.put("longitude", location.longitude)
content.put("latitude", location.latitude)
}
content.put("id_cueillette", 1) // id cueillette a gerer !!
db.insert("CHAMPIGNON", null, content)
db.close()
}
builder.setNegativeButton("Fermer") { _, _ -> }
......
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.mushroomstracker.R
class MyAdapter(private val mList: List<String>) : RecyclerView.Adapter<MyAdapter.ViewHolder>() {
// create new views
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
// inflates the card_view_design view
// that is used to hold list item
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_layout, parent, false)
return ViewHolder(view)
}
// binds the list items to a view
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val ItemsViewModel = mList[position]
// sets the text to the textview from our itemHolder class
holder.textView.text = ItemsViewModel
}
// return the number of the items in the list
override fun getItemCount(): Int {
return mList.size
}
// Holds the views for adding it to image and text
class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
val textView: TextView = itemView.findViewById(R.id.text_view)
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Button
android:id="@+id/button_new_picking"
android:layout_width="388dp"
android:layout_height="48dp"
android:text="@string/main_new_picking"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="16dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="376dp"
android:layout_height="623dp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="147dp"
app:layout_constraintEnd_toEndOf="@id/button_new_picking"
app:layout_constraintStart_toStartOf="@+id/button_new_picking"
app:layout_constraintTop_toTopOf="@id/button_new_picking"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp" />
</LinearLayout>
......@@ -13,5 +13,4 @@
<string name="display_marker_title">Nom du champignon</string>
<string name="display_marker_description">Description</string>
<string name="display_marker_quantite">Quantité</string>
<string name="main_new_picking">Nouvelle cueillette</string>
</resources>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment