Add the ability to add logo to the nav drawer
This commit is contained in:
parent
739934234b
commit
5c37af174d
5 changed files with 60 additions and 1 deletions
|
@ -133,4 +133,6 @@ interface IOsmAndAidlInterface {
|
|||
|
||||
long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback);
|
||||
boolean unregisterFromUpdates(in long callbackId);
|
||||
|
||||
boolean setNavDrawerLogo(in String imageUri);
|
||||
}
|
|
@ -1655,6 +1655,10 @@ public class OsmandAidlApi {
|
|||
}
|
||||
}
|
||||
|
||||
boolean setNavDrawerLogo(@Nullable String uri) {
|
||||
return app.getAppCustomization().setNavDrawerLogo(uri);
|
||||
}
|
||||
|
||||
public static class ConnectedApp implements Comparable<ConnectedApp> {
|
||||
|
||||
static final String PACK_KEY = "pack";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue