mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-25 22:45:41 +03:00
add map via osmdroid
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
c6d3abf421
commit
0742afe58c
6 changed files with 189 additions and 0 deletions
|
@ -286,6 +286,8 @@ dependencies {
|
|||
implementation 'com.github.tobiaskaminsky:ImagePicker:extraFile-SNAPSHOT'
|
||||
implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
|
||||
|
||||
implementation 'org.osmdroid:osmdroid-android:6.1.10'
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.mockito:mockito-core:3.11.0'
|
||||
testImplementation "org.powermock:powermock-core:${powermockVersion}"
|
||||
|
|
|
@ -70,6 +70,8 @@
|
|||
<!-- This permission is deprecated in Android P -->
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
|
||||
<application
|
||||
android:name=".application.NextcloudTalkApplication"
|
||||
android:allowBackup="true"
|
||||
|
|
|
@ -121,6 +121,7 @@ import com.nextcloud.talk.utils.NotificationUtils
|
|||
import com.nextcloud.talk.utils.UriUtils
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NEW_CONVERSATION
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
|
||||
|
@ -795,6 +796,14 @@ class ChatController(args: Bundle) :
|
|||
|
||||
fun showShareLocationScreen(){
|
||||
Log.d(TAG, "showShareLocationScreen")
|
||||
|
||||
val bundle = Bundle()
|
||||
bundle.putBoolean(KEY_NEW_CONVERSATION, true)
|
||||
router.pushController(
|
||||
RouterTransaction.with(LocationController(bundle))
|
||||
.pushChangeHandler(HorizontalChangeHandler())
|
||||
.popChangeHandler(HorizontalChangeHandler())
|
||||
)
|
||||
}
|
||||
|
||||
private fun showConversationInfoScreen() {
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
package com.nextcloud.talk.controllers
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageButton
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.PermissionChecker
|
||||
import androidx.preference.PreferenceManager
|
||||
import autodagger.AutoInjector
|
||||
import butterknife.BindView
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.controllers.base.BaseController
|
||||
import com.nextcloud.talk.utils.preferences.AppPreferences
|
||||
import org.osmdroid.config.Configuration.getInstance
|
||||
import org.osmdroid.tileprovider.tilesource.TileSourceFactory
|
||||
import org.osmdroid.util.GeoPoint
|
||||
import org.osmdroid.views.MapView
|
||||
import org.osmdroid.views.overlay.CopyrightOverlay
|
||||
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider
|
||||
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay
|
||||
import javax.inject.Inject
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class LocationController(args: Bundle) : BaseController(args) {
|
||||
|
||||
@Inject
|
||||
@JvmField
|
||||
var appPreferences: AppPreferences? = null
|
||||
|
||||
@Inject
|
||||
@JvmField
|
||||
var context: Context? = null
|
||||
|
||||
@BindView(R.id.map)
|
||||
@JvmField
|
||||
var map: MapView? = null
|
||||
|
||||
@BindView(R.id.ic_center_map)
|
||||
@JvmField
|
||||
var btCenterMap: ImageButton? = null
|
||||
|
||||
init {
|
||||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||
getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context));
|
||||
}
|
||||
|
||||
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||
return inflater.inflate(R.layout.controller_location, container, false)
|
||||
}
|
||||
|
||||
override fun onAttach(view: View) {
|
||||
super.onAttach(view)
|
||||
drawMap()
|
||||
}
|
||||
|
||||
fun drawMap(){
|
||||
if (!isFineLocationPermissionGranted()) {
|
||||
requestFineLocationPermission();
|
||||
}
|
||||
|
||||
map?.setTileSource(TileSourceFactory.MAPNIK);
|
||||
|
||||
map?.onResume();
|
||||
|
||||
val copyrightOverlay = CopyrightOverlay(context);
|
||||
map?.overlays?.add(copyrightOverlay);
|
||||
|
||||
map?.setMultiTouchControls(true);
|
||||
map?.isTilesScaledToDpi = true;
|
||||
|
||||
val locationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(context), map);
|
||||
locationOverlay.enableFollowLocation();
|
||||
locationOverlay.enableMyLocation();
|
||||
map?.overlays?.add(locationOverlay)
|
||||
|
||||
val mapController = map?.controller
|
||||
mapController?.setZoom(12.0)
|
||||
|
||||
var myLocation: GeoPoint
|
||||
myLocation = GeoPoint(52.0 , 13.0)
|
||||
|
||||
locationOverlay.runOnFirstFix(Runnable {
|
||||
activity!!.runOnUiThread {
|
||||
myLocation = locationOverlay.myLocation
|
||||
mapController?.setCenter(myLocation)
|
||||
}
|
||||
})
|
||||
|
||||
btCenterMap?.setOnClickListener(View.OnClickListener {
|
||||
map?.controller?.animateTo(myLocation)
|
||||
})
|
||||
}
|
||||
|
||||
private fun isFineLocationPermissionGranted(): Boolean {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (PermissionChecker.checkSelfPermission(
|
||||
context!!,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
) == PermissionChecker.PERMISSION_GRANTED
|
||||
) {
|
||||
Log.d(TAG, "Permission is granted")
|
||||
return true
|
||||
} else {
|
||||
Log.d(TAG, "Permission is revoked")
|
||||
return false
|
||||
}
|
||||
} else { //permission is automatically granted on sdk<23 upon installation
|
||||
Log.d(TAG, "Permission is granted")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestFineLocationPermission() {
|
||||
requestPermissions(
|
||||
arrayOf(
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
),
|
||||
REQUEST_PERMISSIONS_REQUEST_CODE
|
||||
)
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
drawMap()
|
||||
} else {
|
||||
Toast.makeText(context, "location permission required!", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = "LocationController"
|
||||
private val REQUEST_PERMISSIONS_REQUEST_CODE = 1;
|
||||
}
|
||||
}
|
10
app/src/main/res/drawable/ic_baseline_gps_fixed_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_gps_fixed_24.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94L13,1h-2v2.06C6.83,3.52 3.52,6.83 3.06,11L1,11v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94L11,23h2v-2.06c4.17,-0.46 7.48,-3.77 7.94,-7.94L23,13v-2h-2.06zM12,19c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z"/>
|
||||
</vector>
|
24
app/src/main/res/layout/controller_location.xml
Normal file
24
app/src/main/res/layout/controller_location.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/parent_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<org.osmdroid.views.MapView android:id="@+id/map"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/ic_center_map"
|
||||
android:src="@drawable/ic_baseline_gps_fixed_24"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:background="#00ffffff"
|
||||
android:cropToPadding="true" />
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue