Support plugin logo

This commit is contained in:
Vitaliy 2020-03-30 19:12:50 +03:00
parent 88d4365e86
commit 7b439dd639
15 changed files with 130 additions and 36 deletions

View file

@ -88,11 +88,6 @@ public class AccessibilityPlugin extends OsmandPlugin {
}
}
@Override
public int getAssetResourceName() {
return 0;
}
@Override
public int getLogoResourceId() {
return R.drawable.ic_plugin_accessibility;

View file

@ -2,6 +2,8 @@ package net.osmand.plus;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -46,6 +48,10 @@ public class CustomOsmandPlugin extends OsmandPlugin {
public String pluginId;
public Map<String, String> names = new HashMap<>();
public Map<String, String> descriptions = new HashMap<>();
public Map<String, String> iconNames = new HashMap<>();
public Map<String, String> imageNames = new HashMap<>();
public Drawable icon;
public Drawable image;
public List<String> rendererNames = new ArrayList<>();
public List<String> routerNames = new ArrayList<>();
@ -205,12 +211,23 @@ public class CustomOsmandPlugin extends OsmandPlugin {
return description;
}
@Override
public int getAssetResourceName() {
return R.drawable.contour_lines;
}
public void readAdditionalDataFromJson(JSONObject json) throws JSONException {
JSONObject iconJson = json.has("icon") ? json.getJSONObject("icon") : null;
if (iconJson != null) {
for (Iterator<String> it = iconJson.keys(); it.hasNext(); ) {
String iconKey = it.next();
String name = iconJson.getString(iconKey);
iconNames.put(iconKey, name);
}
}
JSONObject imageJson = json.has("image") ? json.getJSONObject("image") : null;
if (imageJson != null) {
for (Iterator<String> it = imageJson.keys(); it.hasNext(); ) {
String imageKey = it.next();
String name = imageJson.getString(imageKey);
imageNames.put(imageKey, name);
}
}
JSONObject nameJson = json.has("name") ? json.getJSONObject("name") : null;
if (nameJson != null) {
for (Iterator<String> it = nameJson.keys(); it.hasNext(); ) {
@ -230,6 +247,18 @@ public class CustomOsmandPlugin extends OsmandPlugin {
}
public void writeAdditionalDataToJson(JSONObject json) throws JSONException {
JSONObject iconJson = new JSONObject();
for (Map.Entry<String, String> entry : iconNames.entrySet()) {
iconJson.put(entry.getKey(), entry.getValue());
}
json.put("icon", iconJson);
JSONObject imageJson = new JSONObject();
for (Map.Entry<String, String> entry : imageNames.entrySet()) {
imageJson.put(entry.getKey(), entry.getValue());
}
json.put("image", imageJson);
JSONObject nameJson = new JSONObject();
for (Map.Entry<String, String> entry : names.entrySet()) {
nameJson.put(entry.getKey(), entry.getValue());
@ -288,4 +317,50 @@ public class CustomOsmandPlugin extends OsmandPlugin {
String renderer = RendererRegistry.formatRendererFileName(fileName);
rendererNames.add(renderer.replace('_', ' ').replace('-', ' '));
}
public void updateCustomItems(List<SettingsItem> items) {
for (SettingsItem item : items) {
if (item instanceof SettingsHelper.ResourcesSettingsItem) {
SettingsHelper.ResourcesSettingsItem resourcesSettingsItem = (SettingsHelper.ResourcesSettingsItem) item;
File pluginDir = resourcesSettingsItem.getPluginPath();
File pluginResDir = new File(pluginDir, resourcesSettingsItem.getFileName());
if (pluginResDir.exists() && pluginResDir.isDirectory()) {
File[] files = pluginResDir.listFiles();
for (File resFile : files) {
String path = resFile.getAbsolutePath();
for (Map.Entry<String, String> entry : iconNames.entrySet()) {
String value = entry.getValue();
if (value.startsWith("@")) {
value = value.substring(1);
if (path.endsWith(value)) {
icon = BitmapDrawable.createFromPath(path);
break;
}
}
}
for (Map.Entry<String, String> entry : imageNames.entrySet()) {
String value = entry.getValue();
if (value.startsWith("@")) {
value = value.substring(1);
if (path.endsWith(value)) {
image = BitmapDrawable.createFromPath(path);
break;
}
}
}
}
}
}
}
}
@Override
public int getLogoResourceId() {
return super.getLogoResourceId();
}
@Override
public Drawable getAssetResourceImage() {
return image;
}
}

View file

@ -6,6 +6,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
@ -85,7 +86,15 @@ public abstract class OsmandPlugin {
public abstract String getDescription();
public abstract int getAssetResourceName();
@Nullable
public Drawable getAssetResourceImage() {
return null;
}
@Nullable
public Drawable getLogoResource() {
return app.getUIUtilities().getIcon(getLogoResourceId());
}
@DrawableRes
public int getLogoResourceId() {

View file

@ -65,12 +65,13 @@ public class PluginActivity extends OsmandActionBarActivity implements Download
setContentView(R.layout.plugin);
//noinspection ConstantConditions
getSupportActionBar().setTitle(plugin.getName());
if(plugin.getAssetResourceName() != 0 && Build.VERSION.SDK_INT >= 14) {
Drawable pluginImage = plugin.getAssetResourceImage();
if (pluginImage != null) {
ImageView img = (ImageView) findViewById(R.id.plugin_image);
img.setImageResource(plugin.getAssetResourceName());
img.setImageDrawable(pluginImage);
}
TextView descriptionView = (TextView)findViewById(R.id.plugin_description);
TextView descriptionView = (TextView) findViewById(R.id.plugin_description);
descriptionView.setText(plugin.getDescription());
Button settingsButton = (Button)findViewById(R.id.plugin_settings);

View file

@ -10,6 +10,7 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.AssetFileDescriptor;
import android.graphics.drawable.Drawable;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
@ -2109,8 +2110,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.audio_video_notes;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.audio_video_notes);
}
@Override

View file

@ -2,6 +2,7 @@ package net.osmand.plus.development;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.widget.ArrayAdapter;
import net.osmand.plus.ContextMenuAdapter;
@ -136,8 +137,8 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.osmand_development;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.osmand_development);
}
@Override

View file

@ -41,6 +41,7 @@ import net.osmand.data.FavouritePoint;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.CustomOsmandPlugin;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.OsmandApplication;
@ -844,8 +845,10 @@ public class ImportHelper {
final SettingsImportListener importListener = new SettingsImportListener() {
@Override
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
CustomOsmandPlugin plugin = pluginItem.getPlugin();
plugin.updateCustomItems(items);
if (activity != null) {
pluginItem.getPlugin().onInstall(app, activity);
plugin.onInstall(app, activity);
}
String pluginId = pluginItem.getPluginId();
File pluginDir = new File(app.getAppPath(null), IndexConstants.PLUGINS_DIR + pluginId);

View file

@ -3,6 +3,7 @@ package net.osmand.plus.mapillary;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -71,8 +72,8 @@ public class MapillaryPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.mapillary;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.mapillary);
}
@Override

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
@ -97,8 +98,8 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.trip_recording;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.trip_recording);
}
@Override

View file

@ -1,5 +1,7 @@
package net.osmand.plus.openseamapsplugin;
import android.graphics.drawable.Drawable;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -25,8 +27,8 @@ public class NauticalMapsPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.nautical_map;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.nautical_map);
}
@Override

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
@ -505,11 +506,10 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.osm_editing;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.osm_editing);
}
@Override
public String getHelpFileName() {
return "feature_articles/osm-editing-plugin.html";

View file

@ -4,6 +4,7 @@ package net.osmand.plus.parkingpoint;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.text.format.Time;
@ -505,8 +506,8 @@ public class ParkingPositionPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.parking_position;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.parking_position);
}
@Override

View file

@ -2,6 +2,7 @@ package net.osmand.plus.rastermaps;
import android.app.Activity;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.view.ContextThemeWrapper;
import android.view.View;
@ -85,8 +86,8 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.online_maps;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.online_maps);
}
@Override

View file

@ -1,5 +1,7 @@
package net.osmand.plus.skimapsplugin;
import android.graphics.drawable.Drawable;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -34,8 +36,8 @@ public class SkiMapsPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.ski_map;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.ski_map);
}
@Override

View file

@ -3,6 +3,7 @@ package net.osmand.plus.srtmplugin;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.ArrayAdapter;
@ -82,8 +83,8 @@ public class SRTMPlugin extends OsmandPlugin {
}
@Override
public int getAssetResourceName() {
return R.drawable.contour_lines;
public Drawable getAssetResourceImage() {
return app.getUIUtilities().getIcon(R.drawable.contour_lines);
}
@Override