Use AIDL-API instead of Intents-API for opening OsmAnd
This commit is contained in:
parent
db6b5f7fec
commit
53f4e1319f
7 changed files with 90 additions and 77 deletions
|
@ -51,6 +51,8 @@ import net.osmand.aidl.note.StopRecordingParams;
|
||||||
|
|
||||||
import net.osmand.aidl.gpx.RemoveGpxParams;
|
import net.osmand.aidl.gpx.RemoveGpxParams;
|
||||||
|
|
||||||
|
import net.osmand.aidl.maplayer.ShowLayerPointOnMapParams;
|
||||||
|
|
||||||
// NOTE: Add new methods at the end of file!!!
|
// NOTE: Add new methods at the end of file!!!
|
||||||
|
|
||||||
interface IOsmAndAidlInterface {
|
interface IOsmAndAidlInterface {
|
||||||
|
@ -101,4 +103,6 @@ interface IOsmAndAidlInterface {
|
||||||
boolean navigateGpx(in NavigateGpxParams params);
|
boolean navigateGpx(in NavigateGpxParams params);
|
||||||
|
|
||||||
boolean removeGpx(in RemoveGpxParams params);
|
boolean removeGpx(in RemoveGpxParams params);
|
||||||
|
|
||||||
|
boolean showLayerPointOnMap(in ShowLayerPointOnMapParams params);
|
||||||
}
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
package net.osmand.aidl.maplayer;
|
||||||
|
|
||||||
|
parcelable ShowLayerPointOnMapParams;
|
|
@ -0,0 +1,51 @@
|
||||||
|
package net.osmand.aidl.maplayer;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
public class ShowLayerPointOnMapParams implements Parcelable {
|
||||||
|
|
||||||
|
private String layerId;
|
||||||
|
private String pointId;
|
||||||
|
|
||||||
|
public ShowLayerPointOnMapParams(String layerId, String pointId) {
|
||||||
|
this.layerId = layerId;
|
||||||
|
this.pointId = pointId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShowLayerPointOnMapParams(Parcel in) {
|
||||||
|
layerId = in.readString();
|
||||||
|
pointId = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLayerId() {
|
||||||
|
return layerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPointId() {
|
||||||
|
return pointId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(layerId);
|
||||||
|
dest.writeString(pointId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<ShowLayerPointOnMapParams> CREATOR = new Creator<ShowLayerPointOnMapParams>() {
|
||||||
|
@Override
|
||||||
|
public ShowLayerPointOnMapParams createFromParcel(Parcel in) {
|
||||||
|
return new ShowLayerPointOnMapParams(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShowLayerPointOnMapParams[] newArray(int size) {
|
||||||
|
return new ShowLayerPointOnMapParams[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -20,10 +20,7 @@ import net.osmand.aidl.favorite.group.UpdateFavoriteGroupParams
|
||||||
import net.osmand.aidl.gpx.*
|
import net.osmand.aidl.gpx.*
|
||||||
import net.osmand.aidl.map.ALatLon
|
import net.osmand.aidl.map.ALatLon
|
||||||
import net.osmand.aidl.map.SetMapLocationParams
|
import net.osmand.aidl.map.SetMapLocationParams
|
||||||
import net.osmand.aidl.maplayer.AMapLayer
|
import net.osmand.aidl.maplayer.*
|
||||||
import net.osmand.aidl.maplayer.AddMapLayerParams
|
|
||||||
import net.osmand.aidl.maplayer.RemoveMapLayerParams
|
|
||||||
import net.osmand.aidl.maplayer.UpdateMapLayerParams
|
|
||||||
import net.osmand.aidl.maplayer.point.AMapPoint
|
import net.osmand.aidl.maplayer.point.AMapPoint
|
||||||
import net.osmand.aidl.maplayer.point.AddMapPointParams
|
import net.osmand.aidl.maplayer.point.AddMapPointParams
|
||||||
import net.osmand.aidl.maplayer.point.RemoveMapPointParams
|
import net.osmand.aidl.maplayer.point.RemoveMapPointParams
|
||||||
|
@ -524,6 +521,17 @@ class OsmandAidlHelper(private val app: Application) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showLayerPointOnMap(layerId: String, pointId: String): Boolean {
|
||||||
|
if (mIOsmAndAidlInterface != null) {
|
||||||
|
try {
|
||||||
|
return mIOsmAndAidlInterface!!.showLayerPointOnMap(ShowLayerPointOnMapParams(layerId, pointId))
|
||||||
|
} catch (e: RemoteException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add point to user layer.
|
* Add point to user layer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
package net.osmand.telegram.helpers
|
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.net.Uri
|
|
||||||
import android.support.v4.app.FragmentActivity
|
|
||||||
import net.osmand.telegram.helpers.TelegramUiHelper.ListItem
|
|
||||||
import net.osmand.telegram.ui.MainActivity
|
|
||||||
import net.osmand.telegram.utils.AndroidUtils
|
|
||||||
|
|
||||||
object OsmandHelper {
|
|
||||||
|
|
||||||
private const val PREFIX = "osmand.api://"
|
|
||||||
|
|
||||||
private const val API_CMD_SHOW_LOCATION = "show_location"
|
|
||||||
|
|
||||||
private const val PARAM_LAT = "lat"
|
|
||||||
private const val PARAM_LON = "lon"
|
|
||||||
|
|
||||||
private const val PARAM_AMAP_LAYER_ID = "amap_layer_id"
|
|
||||||
private const val PARAM_AMAP_POINT_ID = "amap_point_id"
|
|
||||||
|
|
||||||
fun showUserOnMap(activity: FragmentActivity?, listItem: ListItem) {
|
|
||||||
if (listItem.canBeOpenedOnMap()) {
|
|
||||||
showLocationPointOnMap(
|
|
||||||
activity,
|
|
||||||
listItem.latLon?.latitude,
|
|
||||||
listItem.latLon?.longitude,
|
|
||||||
listItem.getMapPointId()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun showLocationPointOnMap(
|
|
||||||
activity: FragmentActivity?,
|
|
||||||
lat: Double?,
|
|
||||||
lon: Double?,
|
|
||||||
pointId: String
|
|
||||||
) {
|
|
||||||
if (activity == null || lat == null || lon == null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val params = mapOf(
|
|
||||||
PARAM_LAT to lat.toString(),
|
|
||||||
PARAM_LON to lon.toString(),
|
|
||||||
PARAM_AMAP_LAYER_ID to MAP_LAYER_ID,
|
|
||||||
PARAM_AMAP_POINT_ID to pointId
|
|
||||||
)
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW, createUri(API_CMD_SHOW_LOCATION, params))
|
|
||||||
if (AndroidUtils.isIntentSafe(activity, intent)) {
|
|
||||||
activity.startActivity(intent)
|
|
||||||
} else {
|
|
||||||
MainActivity.OsmandMissingDialogFragment().show(activity.supportFragmentManager, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createUri(command: String, params: Map<String, String>): Uri {
|
|
||||||
val sb = StringBuilder(PREFIX).append(command)
|
|
||||||
if (params.isNotEmpty()) {
|
|
||||||
sb.append("?")
|
|
||||||
params.forEach { (key, value) -> sb.append("$key=$value&") }
|
|
||||||
sb.delete(sb.length - 1, sb.length)
|
|
||||||
}
|
|
||||||
return Uri.parse(sb.toString())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,10 +12,12 @@ import net.osmand.telegram.utils.AndroidUtils
|
||||||
import org.drinkless.td.libcore.telegram.TdApi
|
import org.drinkless.td.libcore.telegram.TdApi
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
const val MAP_LAYER_ID = "telegram_layer"
|
|
||||||
|
|
||||||
class ShowLocationHelper(private val app: TelegramApplication) {
|
class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val MAP_LAYER_ID = "telegram_layer"
|
||||||
|
}
|
||||||
|
|
||||||
private val telegramHelper = app.telegramHelper
|
private val telegramHelper = app.telegramHelper
|
||||||
private val osmandAidlHelper = app.osmandAidlHelper
|
private val osmandAidlHelper = app.osmandAidlHelper
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import net.osmand.telegram.R
|
||||||
import net.osmand.telegram.TelegramApplication
|
import net.osmand.telegram.TelegramApplication
|
||||||
import net.osmand.telegram.TelegramLocationProvider.TelegramCompassListener
|
import net.osmand.telegram.TelegramLocationProvider.TelegramCompassListener
|
||||||
import net.osmand.telegram.TelegramLocationProvider.TelegramLocationListener
|
import net.osmand.telegram.TelegramLocationProvider.TelegramLocationListener
|
||||||
import net.osmand.telegram.helpers.OsmandHelper
|
import net.osmand.telegram.helpers.ShowLocationHelper
|
||||||
import net.osmand.telegram.helpers.TelegramHelper.*
|
import net.osmand.telegram.helpers.TelegramHelper.*
|
||||||
import net.osmand.telegram.helpers.TelegramUiHelper
|
import net.osmand.telegram.helpers.TelegramUiHelper
|
||||||
import net.osmand.telegram.helpers.TelegramUiHelper.ChatItem
|
import net.osmand.telegram.helpers.TelegramUiHelper.ChatItem
|
||||||
|
@ -202,6 +202,12 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showOsmAndMissingDialog() {
|
||||||
|
activity?.let {
|
||||||
|
MainActivity.OsmandMissingDialogFragment().show(it.supportFragmentManager, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inner class LiveNowListAdapter : RecyclerView.Adapter<BaseViewHolder>() {
|
inner class LiveNowListAdapter : RecyclerView.Adapter<BaseViewHolder>() {
|
||||||
|
|
||||||
private val menuList =
|
private val menuList =
|
||||||
|
@ -242,7 +248,14 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
openOnMapView?.isEnabled = canBeOpenedOnMap
|
openOnMapView?.isEnabled = canBeOpenedOnMap
|
||||||
if (canBeOpenedOnMap) {
|
if (canBeOpenedOnMap) {
|
||||||
openOnMapView?.setOnClickListener {
|
openOnMapView?.setOnClickListener {
|
||||||
OsmandHelper.showUserOnMap(activity, item)
|
if (osmandAidlHelper.isOsmandNotInstalled()) {
|
||||||
|
showOsmAndMissingDialog()
|
||||||
|
} else {
|
||||||
|
osmandAidlHelper.showLayerPointOnMap(
|
||||||
|
ShowLocationHelper.MAP_LAYER_ID,
|
||||||
|
item.getMapPointId()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
openOnMapView?.setOnClickListener(null)
|
openOnMapView?.setOnClickListener(null)
|
||||||
|
@ -303,10 +316,7 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
|
||||||
if (settings.hasAnyChatToShowOnMap()) {
|
if (settings.hasAnyChatToShowOnMap()) {
|
||||||
if (osmandAidlHelper.isOsmandNotInstalled()) {
|
if (osmandAidlHelper.isOsmandNotInstalled()) {
|
||||||
if (allSelected) {
|
if (allSelected) {
|
||||||
activity?.let {
|
showOsmAndMissingDialog()
|
||||||
MainActivity.OsmandMissingDialogFragment()
|
|
||||||
.show(it.supportFragmentManager, null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (allSelected) {
|
if (allSelected) {
|
||||||
|
|
Loading…
Reference in a new issue