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