From 5c37af174dba3398fc172eb004020efd6064a0be Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Wed, 31 Oct 2018 15:45:30 +0200 Subject: [PATCH] Add the ability to add logo to the nav drawer --- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 2 ++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 4 +++ .../net/osmand/aidl/OsmandAidlService.java | 6 ++++ .../osmand/plus/OsmAndAppCustomization.java | 34 +++++++++++++++++++ .../plus/activities/MapActivityActions.java | 15 +++++++- 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index d7ebb4492d..83774492c0 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -133,4 +133,6 @@ interface IOsmAndAidlInterface { long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback); boolean unregisterFromUpdates(in long callbackId); + + boolean setNavDrawerLogo(in String imageUri); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index bece844fcb..58d17e998d 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1655,6 +1655,10 @@ public class OsmandAidlApi { } } + boolean setNavDrawerLogo(@Nullable String uri) { + return app.getAppCustomization().setNavDrawerLogo(uri); + } + public static class ConnectedApp implements Comparable { static final String PACK_KEY = "pack"; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index ce61fe4386..bd2ab3e493 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -671,6 +671,12 @@ public class OsmandAidlService extends Service { return true; } + @Override + public boolean setNavDrawerLogo(String imageUri) throws RemoteException { + OsmandAidlApi api = getApi("setNavDrawerLogo"); + return api != null && api.setNavDrawerLogo(imageUri); + } + void startRemoteUpdates(final long updateTimeMS, final long callbackId, final IOsmAndAidlCallback callback) { mHandler.postDelayed(new Runnable() { @Override diff --git a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java index 69037b66c6..098c7a85fc 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java @@ -1,6 +1,11 @@ package net.osmand.plus; import android.app.Activity; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.support.annotation.Nullable; +import android.text.TextUtils; import net.osmand.IProgress; import net.osmand.IndexConstants; @@ -16,6 +21,9 @@ import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.views.OsmandMapTileView; import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.util.Collections; import java.util.List; import java.util.Map; @@ -25,6 +33,8 @@ public class OsmAndAppCustomization { protected OsmandApplication app; protected OsmandSettings osmandSettings; + private Bitmap navDrawerLogo; + public void setup(OsmandApplication app) { this.app = app; this.osmandSettings = new OsmandSettings(app, new net.osmand.plus.api.SettingsAPIImpl(app)); @@ -99,4 +109,28 @@ public class OsmAndAppCustomization { public boolean onDestinationReached() { return true; } + + @Nullable + public Bitmap getNavDrawerLogo() { + return navDrawerLogo; + } + + public boolean setNavDrawerLogo(@Nullable String uri) { + if (TextUtils.isEmpty(uri)) { + navDrawerLogo = null; + } else { + try { + InputStream is = app.getContentResolver().openInputStream(Uri.parse(uri)); + if (is != null) { + navDrawerLogo = BitmapFactory.decodeStream(is); + is.close(); + } + } catch (FileNotFoundException e) { + return false; + } catch (IOException e) { + // ignore + } + } + return true; + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index db6cb0e773..08df53f5bb 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -5,8 +5,10 @@ import android.app.Activity; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.Bitmap; import android.os.AsyncTask; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; @@ -17,9 +19,11 @@ import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; +import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; + import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.Location; @@ -47,7 +51,6 @@ import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.Version; import net.osmand.plus.activities.actions.OsmAndDialogs; -import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dialogs.FavoriteDialogs; import net.osmand.plus.download.IndexItem; @@ -109,10 +112,14 @@ public class MapActivityActions implements DialogProvider { private OsmandSettings settings; private RoutingHelper routingHelper; + @NonNull + private ImageView navDrawerLogoHeader; + public MapActivityActions(MapActivity mapActivity) { this.mapActivity = mapActivity; settings = mapActivity.getMyApplication().getSettings(); routingHelper = mapActivity.getMyApplication().getRoutingHelper(); + navDrawerLogoHeader = new ImageView(mapActivity); } public void addAsTarget(double latitude, double longitude, PointDescription pd) { @@ -957,6 +964,12 @@ public class MapActivityActions implements DialogProvider { } else { menuItemsListView.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.bg_color_light)); } + menuItemsListView.removeHeaderView(navDrawerLogoHeader); + Bitmap navDrawerLogo = getMyApplication().getAppCustomization().getNavDrawerLogo(); + if (navDrawerLogo != null) { + navDrawerLogoHeader.setImageBitmap(navDrawerLogo); + menuItemsListView.addHeaderView(navDrawerLogoHeader); + } menuItemsListView.setDivider(null); final ContextMenuAdapter contextMenuAdapter = createMainOptionsMenu(); contextMenuAdapter.setDefaultLayoutId(R.layout.simple_list_menu_item);