lab8
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.kotlin.android)
|
alias(libs.plugins.kotlin.android)
|
||||||
id("com.google.gms.google-services")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -47,6 +46,5 @@ dependencies {
|
|||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
|
|
||||||
implementation(platform("com.google.firebase:firebase-bom:34.3.0"))
|
implementation("org.osmdroid:osmdroid-android:6.1.20")
|
||||||
implementation("com.google.firebase:firebase-database")
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,11 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
|||||||
@@ -1,50 +1,33 @@
|
|||||||
package com.example.myapplication
|
package com.example.myapplication
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Button
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.widget.EditText
|
import org.osmdroid.config.Configuration
|
||||||
import android.widget.TextView
|
import org.osmdroid.util.GeoPoint
|
||||||
import android.widget.Toast
|
import org.osmdroid.views.MapView
|
||||||
import androidx.activity.ComponentActivity
|
import org.osmdroid.views.overlay.Marker
|
||||||
import com.google.firebase.database.FirebaseDatabase
|
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
private lateinit var map: MapView
|
||||||
private lateinit var etInput: EditText
|
|
||||||
private lateinit var btnSave: Button
|
|
||||||
private lateinit var btnLoad: Button
|
|
||||||
private lateinit var tvResult: TextView
|
|
||||||
|
|
||||||
private val db = FirebaseDatabase.getInstance().reference
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
Configuration.getInstance().load(this, getSharedPreferences("osmdroid", MODE_PRIVATE))
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
etInput = findViewById(R.id.etInput)
|
map = findViewById(R.id.map)
|
||||||
btnSave = findViewById(R.id.btnSave)
|
map.setMultiTouchControls(true)
|
||||||
btnLoad = findViewById(R.id.btnLoad)
|
|
||||||
tvResult = findViewById(R.id.tvResult)
|
|
||||||
|
|
||||||
// Сохранение данных
|
// Координаты Москвы
|
||||||
btnSave.setOnClickListener {
|
val startPoint = GeoPoint(55.751244, 37.618423)
|
||||||
val text = etInput.text.toString()
|
map.controller.setZoom(12.0)
|
||||||
if (text.isNotEmpty()) {
|
map.controller.setCenter(startPoint)
|
||||||
val noteId = db.push().key!! // генерируем уникальный id
|
|
||||||
db.child("notes").child(noteId).setValue(text)
|
|
||||||
Toast.makeText(this, "Сохранено", Toast.LENGTH_SHORT).show()
|
|
||||||
etInput.text.clear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Загрузка данных
|
// Маркер
|
||||||
btnLoad.setOnClickListener {
|
val marker = Marker(map)
|
||||||
db.child("notes").get().addOnSuccessListener { snapshot ->
|
marker.position = startPoint
|
||||||
val list = snapshot.children.mapNotNull { it.getValue(String::class.java) }
|
marker.title = "Москва"
|
||||||
tvResult.text = list.joinToString("\n")
|
map.overlays.add(marker)
|
||||||
}.addOnFailureListener {
|
|
||||||
Toast.makeText(this, "Ошибка загрузки", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,41 +1,4 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<org.osmdroid.views.MapView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/map"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" />
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="16dp">
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/etInput"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:hint="Введите текст" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_marginTop="16dp">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnSave"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="Сохранить" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnLoad"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="Загрузить" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvResult"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:text="Здесь появятся данные"
|
|
||||||
android:textSize="18sp" />
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -2,5 +2,4 @@
|
|||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application) apply false
|
alias(libs.plugins.android.application) apply false
|
||||||
alias(libs.plugins.kotlin.android) apply false
|
alias(libs.plugins.kotlin.android) apply false
|
||||||
id("com.google.gms.google-services") version "4.4.3" apply false
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user