Skip to content
Open
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
20 changes: 8 additions & 12 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 @@ -12,20 +19,9 @@
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}".
-->
<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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
ActivityResultContracts.StartActivityForResult()
) {
if (it.resultCode == CameraActivity.SUCCESS_RESULT_CODE) {
// TODO("Обновить точки на карте при получении результата от камеры")
showPreviewsOnMap()
}
}

Expand All @@ -43,7 +43,7 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {

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

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand All @@ -65,7 +65,6 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {

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

showPreviewsOnMap()
}

Expand All @@ -83,12 +82,12 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
inPreferredConfig = Bitmap.Config.ARGB_8888
}), 64, 64, false
)
// TODO("Указать pinBitmap как иконку для маркера")
map.addMarker(
MarkerOptions()
.position(point)
.icon(BitmapDescriptorFactory.fromBitmap(pinBitmap))
)
// TODO("Передвинуть карту к местоположению последнего фото")
map.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 10f))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sample.otuslocationmapshw.camera

import android.Manifest
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.hardware.Sensor
Expand All @@ -14,6 +15,7 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.camera.core.CameraSelector
import androidx.camera.core.ImageCapture
import androidx.camera.core.ImageCaptureException
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.core.app.ActivityCompat
Expand Down Expand Up @@ -58,9 +60,8 @@ class CameraActivity : AppCompatActivity() {
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
cameraProviderFuture = ProcessCameraProvider.getInstance(this)

// TODO("Получить экземпляр SensorManager")
// TODO("Добавить проверку на наличие датчика акселерометра и присвоить значение tiltSensor")
tiltSensor = TODO("Get tilt sensor")
sensorManager = getSystemService(SENSOR_SERVICE) as SensorManager
tiltSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
cameraProviderFuture.addListener({
cameraProvider = cameraProviderFuture.get()
}, ContextCompat.getMainExecutor(this))
Expand All @@ -81,9 +82,21 @@ class CameraActivity : AppCompatActivity() {
}
}

// TODO("Подписаться на получение событий обновления датчика")
override fun onResume() {
super.onResume()
tiltSensor?.let {
sensorManager.registerListener(
sensorEventListener,
it,
SensorManager.SENSOR_DELAY_NORMAL
)
}
}

// TODO("Остановить получение событий от датчика")
override fun onPause() {
super.onPause()
sensorManager.unregisterListener(sensorEventListener)
}

override fun onRequestPermissionsResult(
requestCode: Int,
Expand Down Expand Up @@ -116,20 +129,39 @@ class CameraActivity : AppCompatActivity() {
folder.mkdirs()
}
val filePath = folderPath + SimpleDateFormat(FILENAME_FORMAT, Locale.getDefault()).format(Date())

// TODO("4. Добавить установку местоположения в метаданные фото")
val outputFileOptions = ImageCapture.OutputFileOptions.Builder(File(filePath))
.setMetadata(ImageCapture.Metadata().also {
it.location = location
})
.build()

// TODO("Добавить вызов CameraX для фото")
// TODO("Вывести Toast о том, что фото успешно сохранено и закрыть текущее активити c указанием кода результата SUCCESS_RESULT_CODE")
// imageCapture...
imageCapture.takePicture(
outputFileOptions,
ContextCompat.getMainExecutor(this),
object : ImageCapture.OnImageSavedCallback {
override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {
Toast.makeText(this@CameraActivity, "Фото сохранено", Toast.LENGTH_SHORT).show()
setResult(SUCCESS_RESULT_CODE)
finish()
}

override fun onError(exception: ImageCaptureException) {
Log.e("CameraX", "Error: ${exception.message}", exception)
}
}
)
}
}

@SuppressLint("MissingPermission")
private fun getLastLocation(callback: (location: Location?) -> Unit) {
// TODO("Добавить получение местоположения от fusedLocationClient и передать результат в callback после получения")
fusedLocationClient.lastLocation
.addOnSuccessListener { location ->
callback(location)
}
.addOnFailureListener { exception ->
Log.e("LOCATION", "Error: ${exception.message}", exception)
callback(null)
}
}

private fun startCamera() {
Expand Down Expand Up @@ -168,9 +200,10 @@ class CameraActivity : AppCompatActivity() {
private const val TAG = "CameraXApp"
private const val FILENAME_FORMAT = "yyyy-MM-dd-HH-mm-ss-SSS"
private const val REQUEST_CODE_PERMISSIONS = 10
// TODO("Указать набор требуемых разрешений")
private val REQUIRED_PERMISSIONS: Array<String> = mutableListOf<String>(
// TODO("Добавить требуемые разрешения")
Manifest.permission.CAMERA,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
).toTypedArray()

const val SUCCESS_RESULT_CODE = 15
Expand Down