Add the ability to add navigation drawer item for opening some app from AIDL API
This commit is contained in:
parent
6d547f45a8
commit
86ca0a3849
12 changed files with 220 additions and 0 deletions
|
@ -53,6 +53,8 @@ import net.osmand.aidl.gpx.RemoveGpxParams;
|
||||||
|
|
||||||
import net.osmand.aidl.maplayer.point.ShowMapPointParams;
|
import net.osmand.aidl.maplayer.point.ShowMapPointParams;
|
||||||
|
|
||||||
|
import net.osmand.aidl.navdrawer.AddOpenAppNavDrawerItemParams;
|
||||||
|
|
||||||
// NOTE: Add new methods at the end of file!!!
|
// NOTE: Add new methods at the end of file!!!
|
||||||
|
|
||||||
interface IOsmAndAidlInterface {
|
interface IOsmAndAidlInterface {
|
||||||
|
@ -105,4 +107,6 @@ interface IOsmAndAidlInterface {
|
||||||
boolean removeGpx(in RemoveGpxParams params);
|
boolean removeGpx(in RemoveGpxParams params);
|
||||||
|
|
||||||
boolean showMapPoint(in ShowMapPointParams params);
|
boolean showMapPoint(in ShowMapPointParams params);
|
||||||
|
|
||||||
|
boolean addOpenAppNavDrawerItem(in AddOpenAppNavDrawerItemParams params);
|
||||||
}
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
package net.osmand.aidl.navdrawer;
|
||||||
|
|
||||||
|
parcelable AddOpenAppNavDrawerItemParams;
|
|
@ -0,0 +1,63 @@
|
||||||
|
package net.osmand.aidl.navdrawer;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
||||||
|
|
||||||
|
private String itemName;
|
||||||
|
private String appPackage;
|
||||||
|
private int flags;
|
||||||
|
|
||||||
|
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage) {
|
||||||
|
this(itemName, appPackage, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage, int flags) {
|
||||||
|
this.itemName = itemName;
|
||||||
|
this.appPackage = appPackage;
|
||||||
|
this.flags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AddOpenAppNavDrawerItemParams(Parcel in) {
|
||||||
|
itemName = in.readString();
|
||||||
|
appPackage = in.readString();
|
||||||
|
flags = in.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemName() {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppPackage() {
|
||||||
|
return appPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFlags() {
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(itemName);
|
||||||
|
dest.writeString(appPackage);
|
||||||
|
dest.writeInt(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<AddOpenAppNavDrawerItemParams> CREATOR = new Creator<AddOpenAppNavDrawerItemParams>() {
|
||||||
|
@Override
|
||||||
|
public AddOpenAppNavDrawerItemParams createFromParcel(Parcel in) {
|
||||||
|
return new AddOpenAppNavDrawerItemParams(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AddOpenAppNavDrawerItemParams[] newArray(int size) {
|
||||||
|
return new AddOpenAppNavDrawerItemParams[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -41,6 +41,15 @@ class TelegramApplication : Application(), OsmandHelperListener {
|
||||||
settings = TelegramSettings(this)
|
settings = TelegramSettings(this)
|
||||||
uiUtils = UiUtils(this)
|
uiUtils = UiUtils(this)
|
||||||
osmandAidlHelper = OsmandAidlHelper(this)
|
osmandAidlHelper = OsmandAidlHelper(this)
|
||||||
|
osmandAidlHelper.listener = object : OsmandAidlHelper.OsmandHelperListener {
|
||||||
|
override fun onOsmandConnectionStateChanged(connected: Boolean) {
|
||||||
|
if (connected) {
|
||||||
|
val basePackage = "net.osmand.telegram"
|
||||||
|
val appPackage = if (BuildConfig.DEBUG) "$basePackage.debug" else basePackage
|
||||||
|
osmandAidlHelper.addOpenAppNavDrawerItem(getString(R.string.app_name), appPackage, -1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
shareLocationHelper = ShareLocationHelper(this)
|
shareLocationHelper = ShareLocationHelper(this)
|
||||||
showLocationHelper = ShowLocationHelper(this)
|
showLocationHelper = ShowLocationHelper(this)
|
||||||
notificationHelper = NotificationHelper(this)
|
notificationHelper = NotificationHelper(this)
|
||||||
|
|
|
@ -33,6 +33,7 @@ import net.osmand.aidl.mapwidget.AMapWidget
|
||||||
import net.osmand.aidl.mapwidget.AddMapWidgetParams
|
import net.osmand.aidl.mapwidget.AddMapWidgetParams
|
||||||
import net.osmand.aidl.mapwidget.RemoveMapWidgetParams
|
import net.osmand.aidl.mapwidget.RemoveMapWidgetParams
|
||||||
import net.osmand.aidl.mapwidget.UpdateMapWidgetParams
|
import net.osmand.aidl.mapwidget.UpdateMapWidgetParams
|
||||||
|
import net.osmand.aidl.navdrawer.AddOpenAppNavDrawerItemParams
|
||||||
import net.osmand.aidl.navigation.NavigateGpxParams
|
import net.osmand.aidl.navigation.NavigateGpxParams
|
||||||
import net.osmand.aidl.navigation.NavigateParams
|
import net.osmand.aidl.navigation.NavigateParams
|
||||||
import net.osmand.aidl.note.StartAudioRecordingParams
|
import net.osmand.aidl.note.StartAudioRecordingParams
|
||||||
|
@ -866,4 +867,15 @@ class OsmandAidlHelper(private val app: Application) {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addOpenAppNavDrawerItem(itemName: String, appPackage: String, flags: Int): Boolean {
|
||||||
|
if (mIOsmAndAidlInterface != null) {
|
||||||
|
try {
|
||||||
|
return mIOsmAndAidlInterface!!.addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams(itemName, appPackage, flags))
|
||||||
|
} catch (e: RemoteException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ import net.osmand.aidl.gpx.RemoveGpxParams;
|
||||||
|
|
||||||
import net.osmand.aidl.maplayer.point.ShowMapPointParams;
|
import net.osmand.aidl.maplayer.point.ShowMapPointParams;
|
||||||
|
|
||||||
|
import net.osmand.aidl.navdrawer.AddOpenAppNavDrawerItemParams;
|
||||||
|
|
||||||
// NOTE: Add new methods at the end of file!!!
|
// NOTE: Add new methods at the end of file!!!
|
||||||
|
|
||||||
interface IOsmAndAidlInterface {
|
interface IOsmAndAidlInterface {
|
||||||
|
@ -105,4 +107,6 @@ interface IOsmAndAidlInterface {
|
||||||
boolean removeGpx(in RemoveGpxParams params);
|
boolean removeGpx(in RemoveGpxParams params);
|
||||||
|
|
||||||
boolean showMapPoint(in ShowMapPointParams params);
|
boolean showMapPoint(in ShowMapPointParams params);
|
||||||
|
|
||||||
|
boolean addOpenAppNavDrawerItem(in AddOpenAppNavDrawerItemParams params);
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.aidl;
|
package net.osmand.aidl;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -12,6 +13,7 @@ import android.os.ParcelFileDescriptor;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
@ -28,6 +30,8 @@ import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
|
import net.osmand.plus.ContextMenuItem;
|
||||||
import net.osmand.plus.FavouritesDbHelper;
|
import net.osmand.plus.FavouritesDbHelper;
|
||||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
|
@ -38,6 +42,7 @@ import net.osmand.plus.MapMarkersHelper;
|
||||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.TargetPointsHelper;
|
import net.osmand.plus.TargetPointsHelper;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||||
|
@ -1186,4 +1191,41 @@ public class OsmandAidlApi {
|
||||||
app.sendBroadcast(intent);
|
app.sendBroadcast(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean addOpenAppNavDrawerItem(String itemName, String appPackage, int flags) {
|
||||||
|
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(appPackage)) {
|
||||||
|
OsmandSettings settings = app.getSettings();
|
||||||
|
settings.API_NAV_DRAWER_ITEM_NAME.set(itemName);
|
||||||
|
settings.API_NAV_DRAWER_ITEM_APP_PACKAGE.set(appPackage);
|
||||||
|
settings.API_NAV_DRAWER_ITEM_FLAGS.set(flags);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerNavDrawerItem(final Activity activity, ContextMenuAdapter adapter) {
|
||||||
|
final OsmandSettings settings = app.getSettings();
|
||||||
|
final String itemName = settings.API_NAV_DRAWER_ITEM_NAME.get();
|
||||||
|
final String appPackage = settings.API_NAV_DRAWER_ITEM_APP_PACKAGE.get();
|
||||||
|
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(appPackage)) {
|
||||||
|
final Intent intent = activity.getPackageManager().getLaunchIntentForPackage(appPackage);
|
||||||
|
if (intent != null) {
|
||||||
|
int flags = settings.API_NAV_DRAWER_ITEM_FLAGS.get();
|
||||||
|
if (flags != -1) {
|
||||||
|
intent.addFlags(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
|
.setTitle(itemName)
|
||||||
|
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
|
||||||
|
activity.startActivity(intent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.createItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import net.osmand.aidl.mapmarker.UpdateMapMarkerParams;
|
||||||
import net.osmand.aidl.mapwidget.AddMapWidgetParams;
|
import net.osmand.aidl.mapwidget.AddMapWidgetParams;
|
||||||
import net.osmand.aidl.mapwidget.RemoveMapWidgetParams;
|
import net.osmand.aidl.mapwidget.RemoveMapWidgetParams;
|
||||||
import net.osmand.aidl.mapwidget.UpdateMapWidgetParams;
|
import net.osmand.aidl.mapwidget.UpdateMapWidgetParams;
|
||||||
|
import net.osmand.aidl.navdrawer.AddOpenAppNavDrawerItemParams;
|
||||||
import net.osmand.aidl.navigation.NavigateGpxParams;
|
import net.osmand.aidl.navigation.NavigateGpxParams;
|
||||||
import net.osmand.aidl.navigation.NavigateParams;
|
import net.osmand.aidl.navigation.NavigateParams;
|
||||||
import net.osmand.aidl.note.StartAudioRecordingParams;
|
import net.osmand.aidl.note.StartAudioRecordingParams;
|
||||||
|
@ -457,5 +458,15 @@ public class OsmandAidlService extends Service {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams params) throws RemoteException {
|
||||||
|
try {
|
||||||
|
return params != null && getApi("addOpenAppNavDrawerItem").addOpenAppNavDrawerItem(params.getItemName(), params.getAppPackage(), params.getFlags());
|
||||||
|
} catch (Exception e) {
|
||||||
|
handleException(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package net.osmand.aidl.navdrawer;
|
||||||
|
|
||||||
|
parcelable AddOpenAppNavDrawerItemParams;
|
|
@ -0,0 +1,63 @@
|
||||||
|
package net.osmand.aidl.navdrawer;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
||||||
|
|
||||||
|
private String itemName;
|
||||||
|
private String appPackage;
|
||||||
|
private int flags;
|
||||||
|
|
||||||
|
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage) {
|
||||||
|
this(itemName, appPackage, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage, int flags) {
|
||||||
|
this.itemName = itemName;
|
||||||
|
this.appPackage = appPackage;
|
||||||
|
this.flags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AddOpenAppNavDrawerItemParams(Parcel in) {
|
||||||
|
itemName = in.readString();
|
||||||
|
appPackage = in.readString();
|
||||||
|
flags = in.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemName() {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppPackage() {
|
||||||
|
return appPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFlags() {
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(itemName);
|
||||||
|
dest.writeString(appPackage);
|
||||||
|
dest.writeInt(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<AddOpenAppNavDrawerItemParams> CREATOR = new Creator<AddOpenAppNavDrawerItemParams>() {
|
||||||
|
@Override
|
||||||
|
public AddOpenAppNavDrawerItemParams createFromParcel(Parcel in) {
|
||||||
|
return new AddOpenAppNavDrawerItemParams(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AddOpenAppNavDrawerItemParams[] newArray(int size) {
|
||||||
|
return new AddOpenAppNavDrawerItemParams[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -742,6 +742,10 @@ public class OsmandSettings {
|
||||||
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", false).makeGlobal();
|
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", false).makeGlobal();
|
||||||
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_MAP_SCREEN = new BooleanPreference("show_dashboard_on_map_screen", false).makeGlobal();
|
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_ITEM_NAME = new StringPreference("api_nav_drawer_item_name", "").makeGlobal();
|
||||||
|
public final CommonPreference<String> API_NAV_DRAWER_ITEM_APP_PACKAGE = new StringPreference("api_nav_drawer_item_app_package", "").makeGlobal();
|
||||||
|
public final CommonPreference<Integer> API_NAV_DRAWER_ITEM_FLAGS = new IntPreference("api_nav_drawer_item_flags", -1).makeGlobal();
|
||||||
|
|
||||||
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
|
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
|
|
|
@ -795,6 +795,8 @@ public class MapActivityActions implements DialogProvider {
|
||||||
}
|
}
|
||||||
}).createItem());
|
}).createItem());
|
||||||
|
|
||||||
|
app.getAidlApi().registerNavDrawerItem(mapActivity, optionsMenuHelper);
|
||||||
|
|
||||||
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.layer_map_appearance, mapActivity)
|
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.layer_map_appearance, mapActivity)
|
||||||
.setIcon(R.drawable.ic_configure_screen_dark)
|
.setIcon(R.drawable.ic_configure_screen_dark)
|
||||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||||
|
|
Loading…
Reference in a new issue