Merge pull request #6127 from osmandapp/aidl_api_improvements
Aidl api improvements
This commit is contained in:
commit
1b97827b45
6 changed files with 295 additions and 96 deletions
|
@ -12,10 +12,12 @@
|
|||
android:id="@+id/plugin_logo"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_margin="8dp"
|
||||
android:background="@drawable/bg_plugin_logo_enabled"
|
||||
android:layout_gravity="center"
|
||||
android:scaleType="center"
|
||||
android:layout_margin="8dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:background="@drawable/bg_plugin_logo_enabled"
|
||||
android:padding="12dp"
|
||||
android:scaleType="fitCenter"
|
||||
tools:src="@drawable/ic_extension_dark" />
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
-->
|
||||
|
||||
<string name="third_party_application">Third-party application</string>
|
||||
<string name="search_street">Search street</string>
|
||||
<string name="start_search_from_city">Start search from city</string>
|
||||
<string name="shared_string_restore">Restore</string>
|
||||
|
|
|
@ -8,11 +8,14 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
|
@ -79,6 +82,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -150,11 +154,13 @@ public class OsmandAidlApi {
|
|||
private Map<String, AMapLayer> layers = new ConcurrentHashMap<>();
|
||||
private Map<String, OsmandMapLayer> mapLayers = new ConcurrentHashMap<>();
|
||||
private Map<String, BroadcastReceiver> receivers = new TreeMap<>();
|
||||
private Map<String, ConnectedApp> connectedApps = new ConcurrentHashMap<>();
|
||||
|
||||
private boolean mapActivityActive = false;
|
||||
|
||||
public OsmandAidlApi(OsmandApplication app) {
|
||||
this.app = app;
|
||||
loadConnectedApps();
|
||||
}
|
||||
|
||||
public void onCreateMapActivity(MapActivity mapActivity) {
|
||||
|
@ -1588,6 +1594,103 @@ public class OsmandAidlApi {
|
|||
return res;
|
||||
}
|
||||
|
||||
public List<ConnectedApp> getConnectedApps() {
|
||||
List<ConnectedApp> res = new ArrayList<>(connectedApps.size());
|
||||
PackageManager pm = app.getPackageManager();
|
||||
for (ConnectedApp app : connectedApps.values()) {
|
||||
try {
|
||||
ApplicationInfo ai = pm.getPackageInfo(app.pack, 0).applicationInfo;
|
||||
app.name = ai.loadLabel(pm).toString();
|
||||
app.icon = ai.loadIcon(pm);
|
||||
res.add(app);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
Collections.sort(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public void switchEnabled(@NonNull ConnectedApp app) {
|
||||
app.enabled = !app.enabled;
|
||||
saveConnectedApps();
|
||||
}
|
||||
|
||||
boolean isAppEnabled(@NonNull String pack) {
|
||||
ConnectedApp app = connectedApps.get(pack);
|
||||
if (app == null) {
|
||||
app = new ConnectedApp(pack, true);
|
||||
connectedApps.put(pack, app);
|
||||
saveConnectedApps();
|
||||
}
|
||||
return app.enabled;
|
||||
}
|
||||
|
||||
private void saveConnectedApps() {
|
||||
try {
|
||||
JSONArray array = new JSONArray();
|
||||
for (ConnectedApp app : connectedApps.values()) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put(ConnectedApp.ENABLED_KEY, app.enabled);
|
||||
obj.put(ConnectedApp.PACK_KEY, app.pack);
|
||||
array.put(obj);
|
||||
}
|
||||
app.getSettings().API_CONNECTED_APPS_JSON.set(array.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConnectedApps() {
|
||||
try {
|
||||
JSONArray array = new JSONArray(app.getSettings().API_CONNECTED_APPS_JSON.get());
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject obj = array.getJSONObject(i);
|
||||
String pack = obj.optString(ConnectedApp.PACK_KEY, "");
|
||||
boolean enabled = obj.optBoolean(ConnectedApp.ENABLED_KEY, true);
|
||||
connectedApps.put(pack, new ConnectedApp(pack, enabled));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConnectedApp implements Comparable<ConnectedApp> {
|
||||
|
||||
static final String PACK_KEY = "pack";
|
||||
static final String ENABLED_KEY = "enabled";
|
||||
|
||||
private String pack;
|
||||
private boolean enabled;
|
||||
private String name;
|
||||
private Drawable icon;
|
||||
|
||||
ConnectedApp(String pack, boolean enabled) {
|
||||
this.pack = pack;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Drawable getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull ConnectedApp app) {
|
||||
if (name != null && app.name != null) {
|
||||
return name.compareTo(app.name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NavDrawerItem {
|
||||
|
||||
static final String NAME_KEY = "name";
|
||||
|
|
|
@ -2,11 +2,13 @@ package net.osmand.aidl;
|
|||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback;
|
||||
|
@ -79,13 +81,19 @@ public class OsmandAidlService extends Service {
|
|||
|
||||
private long updateCallbackId = 0;
|
||||
|
||||
OsmandApplication getApp() {
|
||||
private OsmandApplication getApp() {
|
||||
return (OsmandApplication) getApplication();
|
||||
}
|
||||
|
||||
OsmandAidlApi getApi(String reason) {
|
||||
@Nullable
|
||||
private OsmandAidlApi getApi(String reason) {
|
||||
LOG.info("Request AIDL API for " + reason);
|
||||
return getApp().getAidlApi();
|
||||
OsmandAidlApi api = getApp().getAidlApi();
|
||||
String pack = getApp().getPackageManager().getNameForUid(Binder.getCallingUid());
|
||||
if (pack != null && !pack.equals(getApp().getPackageName()) && !api.isAppEnabled(pack)) {
|
||||
return null;
|
||||
}
|
||||
return api;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,7 +127,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean refreshMap() throws RemoteException {
|
||||
try {
|
||||
return getApi("refreshMap").reloadMap();
|
||||
OsmandAidlApi api = getApi("refreshMap");
|
||||
return api != null && api.reloadMap();
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -130,7 +139,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean addFavoriteGroup(AddFavoriteGroupParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("addFavoriteGroup").addFavoriteGroup(params.getFavoriteGroup());
|
||||
OsmandAidlApi api = getApi("addFavoriteGroup");
|
||||
return params != null && api != null && api.addFavoriteGroup(params.getFavoriteGroup());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -140,7 +150,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean removeFavoriteGroup(RemoveFavoriteGroupParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("removeFavoriteGroup").removeFavoriteGroup(params.getFavoriteGroup());
|
||||
OsmandAidlApi api = getApi("removeFavoriteGroup");
|
||||
return params != null && api != null && api.removeFavoriteGroup(params.getFavoriteGroup());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -150,7 +161,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean updateFavoriteGroup(UpdateFavoriteGroupParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("updateFavoriteGroup").updateFavoriteGroup(params.getFavoriteGroupPrev(), params.getFavoriteGroupNew());
|
||||
OsmandAidlApi api = getApi("updateFavoriteGroup");
|
||||
return params != null && api != null && api.updateFavoriteGroup(params.getFavoriteGroupPrev(), params.getFavoriteGroupNew());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -160,7 +172,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean addFavorite(AddFavoriteParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("addFavorite").addFavorite(params.getFavorite());
|
||||
OsmandAidlApi api = getApi("addFavorite");
|
||||
return params != null && api != null && api.addFavorite(params.getFavorite());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -170,7 +183,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean removeFavorite(RemoveFavoriteParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("removeFavorite").removeFavorite(params.getFavorite());
|
||||
OsmandAidlApi api = getApi("removeFavorite");
|
||||
return params != null && api != null && api.removeFavorite(params.getFavorite());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -180,7 +194,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean updateFavorite(UpdateFavoriteParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("updateFavorite").updateFavorite(params.getFavoritePrev(), params.getFavoriteNew());
|
||||
OsmandAidlApi api = getApi("updateFavorite");
|
||||
return params != null && api != null && api.updateFavorite(params.getFavoritePrev(), params.getFavoriteNew());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -190,7 +205,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean addMapMarker(AddMapMarkerParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("addMapMarker").addMapMarker(params.getMarker());
|
||||
OsmandAidlApi api = getApi("addMapMarker");
|
||||
return params != null && api != null && api.addMapMarker(params.getMarker());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -199,7 +215,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean removeMapMarker(RemoveMapMarkerParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("removeMapMarker").removeMapMarker(params.getMarker());
|
||||
OsmandAidlApi api = getApi("removeMapMarker");
|
||||
return params != null && api != null && api.removeMapMarker(params.getMarker());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -209,7 +226,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean updateMapMarker(UpdateMapMarkerParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("updateMapMarker").updateMapMarker(params.getMarkerPrev(), params.getMarkerNew());
|
||||
OsmandAidlApi api = getApi("updateMapMarker");
|
||||
return params != null && api != null && api.updateMapMarker(params.getMarkerPrev(), params.getMarkerNew());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -219,7 +237,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean addMapWidget(AddMapWidgetParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("addMapWidget").addMapWidget(params.getWidget());
|
||||
OsmandAidlApi api = getApi("addMapWidget");
|
||||
return params != null && api != null && api.addMapWidget(params.getWidget());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -229,7 +248,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean removeMapWidget(RemoveMapWidgetParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("removeMapWidget").removeMapWidget(params.getId());
|
||||
OsmandAidlApi api = getApi("removeMapWidget");
|
||||
return params != null && api != null && api.removeMapWidget(params.getId());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -238,7 +258,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean updateMapWidget(UpdateMapWidgetParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("updateMapWidget").updateMapWidget(params.getWidget());
|
||||
OsmandAidlApi api = getApi("updateMapWidget");
|
||||
return params != null && api != null && api.updateMapWidget(params.getWidget());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -248,7 +269,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean showMapPoint(ShowMapPointParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("showMapPoint").showMapPoint(params.getLayerId(), params.getPoint());
|
||||
OsmandAidlApi api = getApi("showMapPoint");
|
||||
return params != null && api != null && api.showMapPoint(params.getLayerId(), params.getPoint());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -258,7 +280,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean addMapPoint(AddMapPointParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("addMapPoint").putMapPoint(params.getLayerId(), params.getPoint());
|
||||
OsmandAidlApi api = getApi("addMapPoint");
|
||||
return params != null && api != null && api.putMapPoint(params.getLayerId(), params.getPoint());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -268,7 +291,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean removeMapPoint(RemoveMapPointParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("removeMapPoint").removeMapPoint(params.getLayerId(), params.getPointId());
|
||||
OsmandAidlApi api = getApi("removeMapPoint");
|
||||
return params != null && api != null && api.removeMapPoint(params.getLayerId(), params.getPointId());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -278,7 +302,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean updateMapPoint(UpdateMapPointParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("updateMapPoint").putMapPoint(params.getLayerId(), params.getPoint());
|
||||
OsmandAidlApi api = getApi("updateMapPoint");
|
||||
return params != null && api != null && api.putMapPoint(params.getLayerId(), params.getPoint());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -288,7 +313,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean addMapLayer(AddMapLayerParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("addMapLayer").addMapLayer(params.getLayer());
|
||||
OsmandAidlApi api = getApi("addMapLayer");
|
||||
return params != null && api != null && api.addMapLayer(params.getLayer());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -298,7 +324,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean removeMapLayer(RemoveMapLayerParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("removeMapLayer").removeMapLayer(params.getId());
|
||||
OsmandAidlApi api = getApi("removeMapLayer");
|
||||
return params != null && api != null && api.removeMapLayer(params.getId());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -308,7 +335,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean updateMapLayer(UpdateMapLayerParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("updateMapLayer").updateMapLayer(params.getLayer());
|
||||
OsmandAidlApi api = getApi("updateMapLayer");
|
||||
return params != null && api != null && api.updateMapLayer(params.getLayer());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -318,24 +346,28 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean importGpx(ImportGpxParams params) throws RemoteException {
|
||||
if (params != null && !Algorithms.isEmpty(params.getDestinationPath())) {
|
||||
OsmandAidlApi api = getApi("importGpx");
|
||||
if (api != null) {
|
||||
if (params.getGpxFile() != null) {
|
||||
return getApi("importGpx").importGpxFromFile(params.getGpxFile(), params.getDestinationPath(),
|
||||
return api.importGpxFromFile(params.getGpxFile(), params.getDestinationPath(),
|
||||
params.getColor(), params.isShow());
|
||||
} else if (params.getGpxUri() != null) {
|
||||
return getApi("importGpx").importGpxFromUri(params.getGpxUri(), params.getDestinationPath(),
|
||||
return api.importGpxFromUri(params.getGpxUri(), params.getDestinationPath(),
|
||||
params.getColor(), params.isShow());
|
||||
} else if (params.getSourceRawData() != null) {
|
||||
return getApi("importGpx").importGpxFromData(params.getSourceRawData(), params.getDestinationPath(),
|
||||
return api.importGpxFromData(params.getSourceRawData(), params.getDestinationPath(),
|
||||
params.getColor(), params.isShow());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showGpx(ShowGpxParams params) throws RemoteException {
|
||||
if (params != null && params.getFileName() != null) {
|
||||
return getApi("showGpx").showGpx(params.getFileName());
|
||||
OsmandAidlApi api = getApi("showGpx");
|
||||
return api != null && api.showGpx(params.getFileName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -343,20 +375,23 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean hideGpx(HideGpxParams params) throws RemoteException {
|
||||
if (params != null && params.getFileName() != null) {
|
||||
return getApi("hideGpx").hideGpx(params.getFileName());
|
||||
OsmandAidlApi api = getApi("hideGpx");
|
||||
return api != null && api.hideGpx(params.getFileName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActiveGpx(List<ASelectedGpxFile> files) throws RemoteException {
|
||||
return getApi("getActiveGpx").getActiveGpx(files);
|
||||
OsmandAidlApi api = getApi("getActiveGpx");
|
||||
return api != null && api.getActiveGpx(files);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeGpx(RemoveGpxParams params) throws RemoteException {
|
||||
if (params != null && params.getFileName() != null) {
|
||||
return getApi("removeGpx").removeGpx(params.getFileName());
|
||||
OsmandAidlApi api = getApi("removeGpx");
|
||||
return api != null && api.removeGpx(params.getFileName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -364,7 +399,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean setMapLocation(SetMapLocationParams params) throws RemoteException {
|
||||
if (params != null) {
|
||||
return getApi("setMapLocation").setMapLocation(params.getLatitude(), params.getLongitude(),
|
||||
OsmandAidlApi api = getApi("setMapLocation");
|
||||
return api != null && api.setMapLocation(params.getLatitude(), params.getLongitude(),
|
||||
params.getZoom(), params.isAnimated());
|
||||
}
|
||||
return false;
|
||||
|
@ -424,7 +460,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean startGpxRecording(StartGpxRecordingParams params) throws RemoteException {
|
||||
try {
|
||||
return getApi("startGpxRecording").startGpxRecording(params);
|
||||
OsmandAidlApi api = getApi("startGpxRecording");
|
||||
return api != null && api.startGpxRecording(params);
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -434,7 +471,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean stopGpxRecording(StopGpxRecordingParams params) throws RemoteException {
|
||||
try {
|
||||
return getApi("stopGpxRecording").stopGpxRecording(params);
|
||||
OsmandAidlApi api = getApi("stopGpxRecording");
|
||||
return api != null && api.stopGpxRecording(params);
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -444,7 +482,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean takePhotoNote(TakePhotoNoteParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("takePhotoNote").takePhotoNote(params.getLatitude(), params.getLongitude());
|
||||
OsmandAidlApi api = getApi("takePhotoNote");
|
||||
return params != null && api != null && api.takePhotoNote(params.getLatitude(), params.getLongitude());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -454,7 +493,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean startVideoRecording(StartVideoRecordingParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("startVideoRecording").startVideoRecording(params.getLatitude(), params.getLongitude());
|
||||
OsmandAidlApi api = getApi("startVideoRecording");
|
||||
return params != null && api != null && api.startVideoRecording(params.getLatitude(), params.getLongitude());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -464,7 +504,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean startAudioRecording(StartAudioRecordingParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("startAudioRecording").startAudioRecording(params.getLatitude(), params.getLongitude());
|
||||
OsmandAidlApi api = getApi("startAudioRecording");
|
||||
return params != null && api != null && api.startAudioRecording(params.getLatitude(), params.getLongitude());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -474,7 +515,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean stopRecording(StopRecordingParams params) throws RemoteException {
|
||||
try {
|
||||
return getApi("stopRecording").stopRecording();
|
||||
OsmandAidlApi api = getApi("stopRecording");
|
||||
return api != null && api.stopRecording();
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -484,7 +526,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean navigate(NavigateParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("navigate").navigate(
|
||||
OsmandAidlApi api = getApi("navigate");
|
||||
return params != null && api != null && api.navigate(
|
||||
params.getStartName(), params.getStartLat(), params.getStartLon(),
|
||||
params.getDestName(), params.getDestLat(), params.getDestLon(),
|
||||
params.getProfile(), params.isForce());
|
||||
|
@ -497,7 +540,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean navigateGpx(NavigateGpxParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("navigateGpx").navigateGpx(params.getData(), params.getUri(), params.isForce());
|
||||
OsmandAidlApi api = getApi("navigateGpx");
|
||||
return params != null && api != null && api.navigateGpx(params.getData(), params.getUri(), params.isForce());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -507,7 +551,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean pauseNavigation(PauseNavigationParams params) throws RemoteException {
|
||||
try {
|
||||
return getApi("pauseNavigation").pauseNavigation();
|
||||
OsmandAidlApi api = getApi("pauseNavigation");
|
||||
return api != null && api.pauseNavigation();
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -517,7 +562,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean resumeNavigation(ResumeNavigationParams params) throws RemoteException {
|
||||
try {
|
||||
return getApi("resumeNavigation").resumeNavigation();
|
||||
OsmandAidlApi api = getApi("resumeNavigation");
|
||||
return api != null && api.resumeNavigation();
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -527,7 +573,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean stopNavigation(StopNavigationParams params) throws RemoteException {
|
||||
try {
|
||||
return getApi("stopNavigation").stopNavigation();
|
||||
OsmandAidlApi api = getApi("stopNavigation");
|
||||
return api != null && api.stopNavigation();
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -537,7 +584,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean muteNavigation(MuteNavigationParams params) throws RemoteException {
|
||||
try {
|
||||
return getApi("muteNavigation").muteNavigation();
|
||||
OsmandAidlApi api = getApi("muteNavigation");
|
||||
return api != null && api.muteNavigation();
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -547,7 +595,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean unmuteNavigation(UnmuteNavigationParams params) throws RemoteException {
|
||||
try {
|
||||
return getApi("unmuteNavigation").unmuteNavigation();
|
||||
OsmandAidlApi api = getApi("unmuteNavigation");
|
||||
return api != null && api.unmuteNavigation();
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -557,7 +606,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean setNavDrawerItems(SetNavDrawerItemsParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("setNavDrawerItems").setNavDrawerItems(params.getAppPackage(), params.getItems());
|
||||
OsmandAidlApi api = getApi("setNavDrawerItems");
|
||||
return params != null && api != null && api.setNavDrawerItems(params.getAppPackage(), params.getItems());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
@ -567,7 +617,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean search(SearchParams params, final IOsmAndAidlCallback callback) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("search").search(params.getSearchQuery(), params.getSearchType(),
|
||||
OsmandAidlApi api = getApi("search");
|
||||
return params != null && api != null && api.search(params.getSearchQuery(), params.getSearchType(),
|
||||
params.getLatitude(), params.getLongitude(), params.getRadiusLevel(), params.getTotalLimit(), new SearchCompleteCallback() {
|
||||
@Override
|
||||
public void onSearchComplete(List<SearchResult> resultSet) {
|
||||
|
@ -591,7 +642,8 @@ public class OsmandAidlService extends Service {
|
|||
@Override
|
||||
public boolean navigateSearch(NavigateSearchParams params) throws RemoteException {
|
||||
try {
|
||||
return params != null && getApi("navigateSearch").navigateSearch(
|
||||
OsmandAidlApi api = getApi("navigateSearch");
|
||||
return params != null && api != null && api.navigateSearch(
|
||||
params.getStartName(), params.getStartLat(), params.getStartLon(),
|
||||
params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(),
|
||||
params.getProfile(), params.isForce());
|
||||
|
@ -625,7 +677,8 @@ public class OsmandAidlService extends Service {
|
|||
public void run() {
|
||||
try {
|
||||
if (callbacks.containsKey(callbackId)) {
|
||||
if (getApi("isUpdateAllowed").isUpdateAllowed()) {
|
||||
OsmandAidlApi api = getApi("isUpdateAllowed");
|
||||
if (api != null && api.isUpdateAllowed()) {
|
||||
callback.onUpdate();
|
||||
}
|
||||
startRemoteUpdates(updateTimeMS, callbackId, callback);
|
||||
|
|
|
@ -744,6 +744,7 @@ public class OsmandSettings {
|
|||
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_MAP_SCREEN = new BooleanPreference("show_dashboard_on_map_screen", false).makeGlobal();
|
||||
|
||||
public final CommonPreference<String> API_NAV_DRAWER_ITEMS_JSON = new StringPreference("api_nav_drawer_items_json", "{}").makeGlobal();
|
||||
public final CommonPreference<String> API_CONNECTED_APPS_JSON = new StringPreference("api_connected_apps_json", "{}").makeGlobal();
|
||||
|
||||
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
|
||||
|
||||
|
|
|
@ -15,10 +15,13 @@ import android.widget.ImageButton;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.aidl.OsmandAidlApi.ConnectedApp;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PluginsActivity extends OsmandListActivity {
|
||||
|
||||
public static final int ACTIVE_PLUGINS_LIST_MODIFIED = 1;
|
||||
|
@ -27,7 +30,7 @@ public class PluginsActivity extends OsmandListActivity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((OsmandApplication) getApplication()).applyTheme(this);
|
||||
getMyApplication().applyTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.plugins);
|
||||
getSupportActionBar().setTitle(R.string.plugins_screen);
|
||||
|
@ -46,6 +49,8 @@ public class PluginsActivity extends OsmandListActivity {
|
|||
Intent intent = new Intent(this, PluginActivity.class);
|
||||
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, ((OsmandPlugin) tag).getId());
|
||||
startActivity(intent);
|
||||
} else if (tag instanceof ConnectedApp) {
|
||||
switchEnabled((ConnectedApp) tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +61,7 @@ public class PluginsActivity extends OsmandListActivity {
|
|||
}
|
||||
|
||||
private void enableDisablePlugin(OsmandPlugin plugin, boolean enable) {
|
||||
OsmandApplication app = (OsmandApplication) getApplication();
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (OsmandPlugin.enablePlugin(this, app, plugin, enable)) {
|
||||
if (!listModified) {
|
||||
setResult(ACTIVE_PLUGINS_LIST_MODIFIED);
|
||||
|
@ -66,10 +71,17 @@ public class PluginsActivity extends OsmandListActivity {
|
|||
}
|
||||
}
|
||||
|
||||
protected class PluginsListAdapter extends ArrayAdapter<OsmandPlugin> {
|
||||
private void switchEnabled(@NonNull ConnectedApp app) {
|
||||
getMyApplication().getAidlApi().switchEnabled(app);
|
||||
getListAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
protected class PluginsListAdapter extends ArrayAdapter<Object> {
|
||||
|
||||
PluginsListAdapter() {
|
||||
super(PluginsActivity.this, R.layout.plugins_list_item, OsmandPlugin.getVisiblePlugins());
|
||||
super(PluginsActivity.this, R.layout.plugins_list_item, new ArrayList<>());
|
||||
addAll(getMyApplication().getAidlApi().getConnectedApps());
|
||||
addAll(OsmandPlugin.getVisiblePlugins());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -80,43 +92,53 @@ public class PluginsActivity extends OsmandListActivity {
|
|||
view = getLayoutInflater().inflate(R.layout.plugins_list_item, parent, false);
|
||||
}
|
||||
|
||||
final OsmandPlugin plugin = getItem(position);
|
||||
final Object item = getItem(position);
|
||||
|
||||
view.setTag(plugin);
|
||||
boolean active = false;
|
||||
int logoContDescId = R.string.shared_string_disable;
|
||||
String name = "";
|
||||
|
||||
ImageButton pluginLogo = (ImageButton) view.findViewById(R.id.plugin_logo);
|
||||
pluginLogo.setImageResource(plugin.getLogoResourceId());
|
||||
if (plugin.isActive()) {
|
||||
pluginLogo.setBackgroundResource(R.drawable.bg_plugin_logo_enabled);
|
||||
pluginLogo.setContentDescription(getString(R.string.shared_string_disable));
|
||||
} else {
|
||||
TypedArray attributes = getTheme().obtainStyledAttributes(
|
||||
new int[]{R.attr.bg_plugin_logo_disabled});
|
||||
pluginLogo.setBackgroundDrawable(attributes.getDrawable(0));
|
||||
pluginLogo.setContentDescription(getString(plugin.needsInstallation() ? R.string.access_shared_string_not_installed : R.string.shared_string_enable));
|
||||
attributes.recycle();
|
||||
ImageView pluginOptions = (ImageView) view.findViewById(R.id.plugin_options);
|
||||
TextView pluginDescription = (TextView) view.findViewById(R.id.plugin_description);
|
||||
|
||||
if (item instanceof ConnectedApp) {
|
||||
final ConnectedApp app = (ConnectedApp) item;
|
||||
active = app.isEnabled();
|
||||
if (!active) {
|
||||
logoContDescId = R.string.shared_string_enable;
|
||||
}
|
||||
name = app.getName();
|
||||
pluginDescription.setText(R.string.third_party_application);
|
||||
pluginLogo.setImageDrawable(app.getIcon());
|
||||
pluginLogo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!plugin.isActive() && plugin.needsInstallation()) {
|
||||
// nothing
|
||||
} else {
|
||||
switchEnabled(app);
|
||||
}
|
||||
});
|
||||
pluginOptions.setVisibility(View.GONE);
|
||||
pluginOptions.setOnClickListener(null);
|
||||
view.setTag(app);
|
||||
} else if (item instanceof OsmandPlugin) {
|
||||
final OsmandPlugin plugin = (OsmandPlugin) item;
|
||||
active = plugin.isActive();
|
||||
if (!active) {
|
||||
logoContDescId = plugin.needsInstallation()
|
||||
? R.string.access_shared_string_not_installed : R.string.shared_string_enable;
|
||||
}
|
||||
name = plugin.getName();
|
||||
pluginDescription.setText(plugin.getDescription());
|
||||
pluginLogo.setImageResource(plugin.getLogoResourceId());
|
||||
pluginLogo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (plugin.isActive() || !plugin.needsInstallation()) {
|
||||
enableDisablePlugin(plugin, !plugin.isActive());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
TextView pluginName = (TextView) view.findViewById(R.id.plugin_name);
|
||||
pluginName.setText(plugin.getName());
|
||||
pluginName.setContentDescription(plugin.getName() + " " + getString(plugin.isActive()
|
||||
? R.string.item_checked
|
||||
: R.string.item_unchecked));
|
||||
|
||||
TextView pluginDescription = (TextView) view.findViewById(R.id.plugin_description);
|
||||
pluginDescription.setText(plugin.getDescription());
|
||||
|
||||
ImageView pluginOptions = (ImageView) view.findViewById(R.id.plugin_options);
|
||||
pluginOptions.setVisibility(View.VISIBLE);
|
||||
pluginOptions.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white));
|
||||
pluginOptions.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -124,6 +146,23 @@ public class PluginsActivity extends OsmandListActivity {
|
|||
showOptionsMenu(v, plugin);
|
||||
}
|
||||
});
|
||||
view.setTag(plugin);
|
||||
}
|
||||
|
||||
pluginLogo.setContentDescription(getString(logoContDescId));
|
||||
if (active) {
|
||||
pluginLogo.setBackgroundResource(R.drawable.bg_plugin_logo_enabled);
|
||||
} else {
|
||||
TypedArray attributes = getTheme().obtainStyledAttributes(new int[]{R.attr.bg_plugin_logo_disabled});
|
||||
pluginLogo.setBackgroundDrawable(attributes.getDrawable(0));
|
||||
attributes.recycle();
|
||||
}
|
||||
|
||||
TextView pluginName = (TextView) view.findViewById(R.id.plugin_name);
|
||||
pluginName.setText(name);
|
||||
pluginName.setContentDescription(name + " " + getString(active
|
||||
? R.string.item_checked
|
||||
: R.string.item_unchecked));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue