Skip to content
Open

done #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ plugins {

android {
namespace 'com.sample.otuslocationmapshw'
compileSdk 35
compileSdk 36

defaultConfig {
applicationId "com.sample.otuslocationmapshw"
minSdk 23
targetSdk 35
targetSdk 36
versionCode 1
versionName "1.0"

Expand All @@ -38,18 +38,18 @@ android {

dependencies {

implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'com.google.android.gms:play-services-maps:19.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'androidx.camera:camera-core:1.4.1'
implementation 'androidx.camera:camera-lifecycle:1.4.1'
implementation 'androidx.camera:camera-camera2:1.4.1'
implementation 'androidx.camera:camera-view:1.4.1'
implementation 'androidx.core:core-ktx:1.17.0'
implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'com.google.android.material:material:1.13.0'
implementation 'com.google.android.gms:play-services-maps:20.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
implementation 'androidx.camera:camera-core:1.5.3'
implementation 'androidx.camera:camera-lifecycle:1.5.3'
implementation 'androidx.camera:camera-camera2:1.5.3'
implementation 'androidx.camera:camera-view:1.5.3'
implementation 'com.google.android.gms:play-services-location:21.3.0'
implementation 'androidx.exifinterface:exifinterface:1.3.7'
implementation 'androidx.exifinterface:exifinterface:1.4.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
}
23 changes: 9 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-feature
android:name="android.hardware.camera"
android:required="false"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -10,22 +17,10 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.OTUSLocationMapsHW"
tools:targetApi="31">
<!--
TODO: Before you run your application, you need a Google Maps API key.

To get one, follow the directions here:

https://developers.google.com/maps/documentation/android-sdk/get-api-key

Once you have your API key (it starts with "AIza"), define a new property in your
project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the
"YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".
-->
android:theme="@style/Theme.OTUSLocationMapsHW" >
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />
android:value="${MAPS_API_KEY}" />

<activity
android:name=".MapsActivity"
Expand Down
51 changes: 27 additions & 24 deletions app/src/main/java/com/sample/otuslocationmapshw/MapsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,71 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var binding: ActivityMapsBinding

private val locationDataUtils = LocationDataUtils()
private val cameraForResultLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) {
if (it.resultCode == CameraActivity.SUCCESS_RESULT_CODE) {
// TODO("Обновить точки на карте при получении результата от камеры")

private val cameraForResultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == CameraActivity.SUCCESS_RESULT_CODE) showPreviewsOnMap()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityMapsBinding.inflate(layoutInflater)
setContentView(binding.root)

val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
// TODO("Вызвать инициализацию карты")
(supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment)
.getMapAsync(this)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.action_menu, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
R.id.action_add -> {
cameraForResultLauncher.launch(Intent(this, CameraActivity::class.java))
true
}
else -> {
super.onOptionsItemSelected(item)
}
else -> super.onOptionsItemSelected(item)
}
}

override fun onMapReady(googleMap: GoogleMap) {
map = googleMap

showPreviewsOnMap()
}

private fun showPreviewsOnMap() {
map.clear()

val folder = File("${filesDir.absolutePath}/photos/")
folder.listFiles()?.forEach {
val exifInterface = ExifInterface(it)
val location = locationDataUtils.getLocationFromExif(exifInterface)

folder.listFiles()?.forEach { file ->

val exif = ExifInterface(file)
val location = locationDataUtils.getLocationFromExif(exif)
val point = LatLng(location.latitude, location.longitude)
val pinBitmap = Bitmap.createScaledBitmap(

val bitmap = Bitmap.createScaledBitmap(
BitmapFactory.decodeFile(
it.path,
file.path,
BitmapFactory.Options().apply {
inPreferredConfig = Bitmap.Config.ARGB_8888
}), 64, 64, false
}
),
64,
64,
false
)
// TODO("Указать pinBitmap как иконку для маркера")

map.addMarker(
MarkerOptions()
.position(point)
.icon(BitmapDescriptorFactory.fromBitmap(bitmap))
)
// TODO("Передвинуть карту к местоположению последнего фото")

map.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 10f))
}
}
}
Loading