-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Release] - v0.2 - Release to master - PR
[Release] - v0.2 - Release to master
- Loading branch information
Showing
13 changed files
with
293 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
app/src/main/java/com/archaeologicalfieldwork/activities/MapActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/archaeologicalfieldwork/helpers/ImageHelpers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
Oops, something went wrong.