Skip to content

Commit

Permalink
[Release] - v0.2 - Release to master - PR
Browse files Browse the repository at this point in the history
[Release] -  v0.2 - Release to master
  • Loading branch information
philippluxi authored Jan 1, 2021
2 parents 19f2b01 + dfeba61 commit c62fb8f
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/captures
.externalNativeBuild
.cxx
/app/src/release/res/values/google_maps_api.xml
/app/src/debug/res/values/google_maps_api.xml
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

Expand Down
50 changes: 30 additions & 20 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.archaeologicalfieldwork">

<application
android:name="com.archaeologicalfieldwork.main.MainApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".activities.SpotActivity"></activity>

<activity android:name=".activities.SpotListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:name=".main.MainApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".activities.SpotActivity" />
<activity android:name=".activities.SpotListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<activity
android:name=".activities.MapActivity"
android:label="@string/title_activity_map"></activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.archaeologicalfieldwork.activities

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
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.archaeologicalfieldwork.R
import com.archaeologicalfieldwork.models.Location

class MapActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarkerDragListener,
GoogleMap.OnMarkerClickListener {

private lateinit var Map: GoogleMap
var location = Location()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map)
location = intent.extras?.getParcelable<Location>("location")!!

val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
}

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

val loc = LatLng(location.lat, location.lng)
val options = MarkerOptions()
.title("Spot")
.snippet("GPS: " + loc.toString())
.draggable(true)
.position(loc)

Map.addMarker(options)
Map.setOnMarkerDragListener(this)
Map.setOnMarkerClickListener(this)
Map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, location.zoom))
}

override fun onMarkerDragStart(marker: Marker) {
}

override fun onMarkerDrag(marker: Marker) {
}

override fun onMarkerDragEnd(marker: Marker) {
location.lat = marker.position.latitude
location.lng = marker.position.longitude
location.zoom = Map.cameraPosition.zoom
}

override fun onMarkerClick(marker: Marker): Boolean {
val loc = LatLng(location.lat, location.lng)
marker.setSnippet("GPS: " + loc.toString())
return false
}

override fun onBackPressed() {
val resultIntent = Intent()
resultIntent.putExtra("location", location)
setResult(Activity.RESULT_OK, resultIntent)
finish()
super.onBackPressed()
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.archaeologicalfieldwork.activities

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_spot.*
import org.jetbrains.anko.info
import org.jetbrains.anko.toast
import org.jetbrains.anko.intentFor
import org.jetbrains.anko.AnkoLogger
import com.archaeologicalfieldwork.R
import com.archaeologicalfieldwork.helpers.readImage
import com.archaeologicalfieldwork.helpers.readImageFromPath
import com.archaeologicalfieldwork.helpers.showImagePicker
import com.archaeologicalfieldwork.main.MainApp
import com.archaeologicalfieldwork.models.Location
import com.archaeologicalfieldwork.models.SpotModel

class SpotActivity : AppCompatActivity(), AnkoLogger {
Expand All @@ -18,6 +24,9 @@ class SpotActivity : AppCompatActivity(), AnkoLogger {
lateinit var app: MainApp
var edit = false

val IMAGE_REQUEST = 1
val LOCATION_REQUEST = 2

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_spot)
Expand All @@ -34,6 +43,10 @@ class SpotActivity : AppCompatActivity(), AnkoLogger {
spot = intent.extras?.getParcelable<SpotModel>("spot_edit")!!
spotTitle.setText(spot.title)
spotDescription.setText(spot.desription)
spotImage.setImageBitmap(readImageFromPath(this, spot.image))
if (spot.image != null) {
btnChooseImage.setText(R.string.change_spot_image)
}

btnAddSpot.setText(R.string.button_save_spot)
}
Expand All @@ -57,6 +70,25 @@ class SpotActivity : AppCompatActivity(), AnkoLogger {
finish()
}
}

// Handle Add Image Button Press
btnChooseImage.setOnClickListener {
showImagePicker(this, IMAGE_REQUEST)
}

// Handle Set Location Button Press
btnSetLocation.setOnClickListener {
val location = Location(48.983307948993094, 12.105706251194382, 16f)
if (spot.zoom != 0F) {
location.lat = spot.lat
location.lng = spot.lng
location.zoom = spot.zoom
}
startActivityForResult(
intentFor<MapActivity>().putExtra("location", location),
LOCATION_REQUEST
)
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand All @@ -72,4 +104,25 @@ class SpotActivity : AppCompatActivity(), AnkoLogger {
}
return super.onOptionsItemSelected(item)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
IMAGE_REQUEST -> {
if (data != null) {
spot.image = data.getData().toString()
spotImage.setImageBitmap((readImage(this, resultCode, data)))
btnChooseImage.setText(R.string.change_spot_image)
}
}
LOCATION_REQUEST -> {
if (data != null) {
val location = data.extras?.getParcelable<Location>("location")!!
spot.lat = location.lat
spot.lng = location.lng
spot.zoom = location.zoom
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.LayoutInflater
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.card_spot.view.*
import com.archaeologicalfieldwork.R
import com.archaeologicalfieldwork.helpers.readImageFromPath
import com.archaeologicalfieldwork.models.SpotModel

interface SpotListener {
Expand Down Expand Up @@ -39,6 +40,7 @@ class SpotAdapter constructor(
fun bind(spot: SpotModel, listener: SpotListener) {
itemView.spotTitle_Card.text = spot.title
itemView.spotDescription_Card.text = spot.desription
itemView.imageIcon.setImageBitmap(readImageFromPath(itemView.context, spot.image))
itemView.setOnClickListener { listener.onSpotClick(spot) }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.archaeologicalfieldwork.helpers

import android.net.Uri
import android.app.Activity
import android.content.Intent
import android.content.Context
import android.graphics.Bitmap
import android.provider.MediaStore
import android.graphics.BitmapFactory
import java.io.IOException
import com.archaeologicalfieldwork.R


fun showImagePicker(parent: Activity, id: Int) {
val intent = Intent()
intent.type = "image/*"
intent.action = Intent.ACTION_OPEN_DOCUMENT
intent.addCategory(Intent.CATEGORY_OPENABLE)

val chooser = Intent.createChooser(intent, R.string.select_spot_image.toString())
parent.startActivityForResult(chooser, id)
}

fun readImage(activity: Activity, resultCode: Int, data: Intent?): Bitmap? {
var bitmap: Bitmap? = null
if (resultCode == Activity.RESULT_OK && data != null && data.data != null) {
try {
bitmap = MediaStore.Images.Media.getBitmap(activity.contentResolver, data.data)
} catch (e: IOException) {
e.printStackTrace()
}
}
return bitmap
}

fun readImageFromPath(context: Context, path: String): Bitmap? {
var bitmap: Bitmap? = null
val uri = Uri.parse(path)
if (uri != null) {
try {
val parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r")
val fileDescriptor = parcelFileDescriptor?.getFileDescriptor()
bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor)
parcelFileDescriptor?.close()
} catch (e: Exception) {
}
}
return bitmap
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class SpotMemStore : SpotStore, AnkoLogger {
if (foundSpot != null) {
foundSpot.title = spot.title
foundSpot.desription = spot.desription
foundSpot.image = spot.image
foundSpot.lat = spot.lat
foundSpot.lng = spot.lng
foundSpot.zoom = spot.zoom
logAll()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,16 @@ import kotlinx.android.parcel.Parcelize
data class SpotModel(
var id: Long = 0,
var title: String = "",
var desription: String = ""
var desription: String = "",
var image: String = "",
var lat: Double = 0.0,
var lng: Double = 0.0,
var zoom: Float = 0f
) : Parcelable

@Parcelize
data class Location(
var lat: Double = 0.0,
var lng: Double = 0.0,
var zoom: Float = 0f
) : Parcelable
9 changes: 9 additions & 0 deletions app/src/main/res/layout/activity_map.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MapActivity" />
Loading

0 comments on commit c62fb8f

Please sign in to comment.