update plugins

This commit is contained in:
Victor Shcherb 2015-02-09 00:48:31 +01:00
parent 96fa01d724
commit 8d6a4a19e3
20 changed files with 195 additions and 95 deletions

View file

@ -9,6 +9,10 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="plugin_ski_name">Ski Maps</string>
<string name="plugin_nautical_name">Nautical Maps</string>
<string name="world_ski_missing">In order to display ski maps, the special offline map needs to be downloaded</string>
<string name="nautical_maps_missing">In order to display nautical maps, the special offline map needs to be downloaded</string>
<string name="edit_group">Edit group</string> <string name="edit_group">Edit group</string>
<string name="parking_place">Parking place</string> <string name="parking_place">Parking place</string>
<string name="remove_the_tag">REMOVE THE TAG</string> <string name="remove_the_tag">REMOVE THE TAG</string>

View file

@ -20,7 +20,7 @@ public class AccessibilityPlugin extends OsmandPlugin {
} }
@Override @Override
public boolean init(OsmandApplication app) { public boolean init(OsmandApplication app, Activity activity) {
return true; return true;
} }

View file

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.widget.CompoundButton.OnCheckedChangeListener;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
@ -18,7 +19,7 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.distancecalculator.DistanceCalculatorPlugin; import net.osmand.plus.distancecalculator.DistanceCalculatorPlugin;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.openseamapsplugin.OpenSeaMapsPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmo.OsMoPlugin; import net.osmand.plus.osmo.OsMoPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
@ -62,8 +63,9 @@ public abstract class OsmandPlugin {
/** /**
* Initialize plugin runs just after creation * Initialize plugin runs just after creation
* @param activity TODO
*/ */
public abstract boolean init(OsmandApplication app); public abstract boolean init(OsmandApplication app, Activity activity);
public void setActive(boolean active) { public void setActive(boolean active) {
this.active = active; this.active = active;
@ -100,7 +102,7 @@ public abstract class OsmandPlugin {
checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null); checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null);
allPlugins.add(new AudioVideoNotesPlugin(app)); allPlugins.add(new AudioVideoNotesPlugin(app));
checkMarketPlugin(app, new RoutePointsPlugin(app), false /*FIXME*/, RoutePointsPlugin.ROUTE_POINTS_PLUGIN_COMPONENT, null); checkMarketPlugin(app, new RoutePointsPlugin(app), false /*FIXME*/, RoutePointsPlugin.ROUTE_POINTS_PLUGIN_COMPONENT, null);
checkMarketPlugin(app, new OpenSeaMapsPlugin(app), false, OpenSeaMapsPlugin.COMPONENT, null); checkMarketPlugin(app, new NauticalMapsPlugin(app), false, NauticalMapsPlugin.COMPONENT, null);
checkMarketPlugin(app, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null); checkMarketPlugin(app, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null);
allPlugins.add(new DistanceCalculatorPlugin(app)); allPlugins.add(new DistanceCalculatorPlugin(app));
allPlugins.add(new AccessibilityPlugin(app)); allPlugins.add(new AccessibilityPlugin(app));
@ -110,7 +112,7 @@ public abstract class OsmandPlugin {
for (OsmandPlugin plugin : allPlugins) { for (OsmandPlugin plugin : allPlugins) {
if (enabledPlugins.contains(plugin.getId()) || plugin.isActive()) { if (enabledPlugins.contains(plugin.getId()) || plugin.isActive()) {
try { try {
if (plugin.init(app)) { if (plugin.init(app, null)) {
plugin.setActive(true); plugin.setActive(true);
} }
} catch (Exception e) { } catch (Exception e) {
@ -141,9 +143,9 @@ public abstract class OsmandPlugin {
} }
} }
public static boolean enablePlugin(OsmandApplication app, OsmandPlugin plugin, boolean enable) { public static boolean enablePlugin(Activity activity, OsmandApplication app, OsmandPlugin plugin, boolean enable) {
if (enable) { if (enable) {
if (!plugin.init(app)) { if (!plugin.init(app, activity)) {
plugin.setActive(false); plugin.setActive(false);
return false; return false;
} else { } else {

View file

@ -77,7 +77,7 @@ public class PluginActivity extends OsmandActionBarActivity {
return; return;
} }
boolean ok = OsmandPlugin.enablePlugin((OsmandApplication)getApplication(), boolean ok = OsmandPlugin.enablePlugin(PluginActivity.this, (OsmandApplication)getApplication(),
plugin, isChecked); plugin, isChecked);
if (!ok) { if (!ok) {
return; return;

View file

@ -51,7 +51,7 @@ public class PluginsActivity extends OsmandListActivity {
} }
private void enableDisablePlugin(OsmandPlugin plugin, boolean enable) { private void enableDisablePlugin(OsmandPlugin plugin, boolean enable) {
boolean ok = OsmandPlugin.enablePlugin(((OsmandApplication) getApplication()), plugin, boolean ok = OsmandPlugin.enablePlugin(this, ((OsmandApplication) getApplication()), plugin,
enable); enable);
if (!ok) { if (!ok) {
return; return;
@ -94,7 +94,11 @@ public class PluginsActivity extends OsmandListActivity {
pluginLogo.setOnClickListener(new View.OnClickListener() { pluginLogo.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
enableDisablePlugin(plugin, !plugin.isActive()); if(!plugin.isActive() && plugin.needsInstallation()) {
// nothing
} else {
enableDisablePlugin(plugin, !plugin.isActive());
}
} }
}); });
@ -126,18 +130,20 @@ public class PluginsActivity extends OsmandListActivity {
final Class<? extends Activity> settingsActivity = plugin.getSettingsActivity(); final Class<? extends Activity> settingsActivity = plugin.getSettingsActivity();
final PopupMenu optionsMenu = new PopupMenu(this, v); final PopupMenu optionsMenu = new PopupMenu(this, v);
if (plugin.isActive() || !plugin.needsInstallation()) {
MenuItem enableDisableItem = optionsMenu.getMenu().add(plugin.isActive() MenuItem enableDisableItem = optionsMenu.getMenu().add(
? R.string.disable_plugin2 plugin.isActive() ? R.string.disable_plugin2
: R.string.enable_plugin2); : R.string.enable_plugin2);
enableDisableItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { enableDisableItem
@Override .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) { @Override
enableDisablePlugin(plugin, !plugin.isActive()); public boolean onMenuItemClick(MenuItem item) {
optionsMenu.dismiss(); enableDisablePlugin(plugin, !plugin.isActive());
return true; optionsMenu.dismiss();
} return true;
}); }
});
}
if (settingsActivity != null) { if (settingsActivity != null) {
MenuItem settingsItem = optionsMenu.getMenu().add(R.string.settings); MenuItem settingsItem = optionsMenu.getMenu().add(R.string.settings);

View file

@ -366,7 +366,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
@Override @Override
public boolean init(final OsmandApplication app) { public boolean init(final OsmandApplication app, Activity activity) {
initializeRemoteControlRegistrationMethods(); initializeRemoteControlRegistrationMethods();
AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE);
if (am != null) { if (am != null) {

View file

@ -37,22 +37,12 @@ public class DashPluginsFragment extends DashBaseFragment {
if (plugin.isActive() == isChecked || plugin.needsInstallation()) { if (plugin.isActive() == isChecked || plugin.needsInstallation()) {
return; return;
} }
if (OsmandPlugin.enablePlugin(getMyApplication(), plugin, isChecked)) { if (OsmandPlugin.enablePlugin(getActivity(), getMyApplication(), plugin, isChecked)) {
updatePluginState(pluginView); updatePluginState(pluginView);
} }
} }
}; };
private final View.OnClickListener toggleEnableDisableListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
View pluginView = AndroidUtils.findParentViewById(view, R.id.dash_plugin_item);
OsmandPlugin plugin = (OsmandPlugin)pluginView.getTag();
if (OsmandPlugin.enablePlugin(getMyApplication(), plugin, !plugin.isActive())) {
updatePluginState(pluginView);
}
}
};
private final View.OnClickListener getListener = new View.OnClickListener() { private final View.OnClickListener getListener = new View.OnClickListener() {
@Override @Override
@ -164,7 +154,6 @@ public class DashPluginsFragment extends DashBaseFragment {
nameView.setText(plugin.getName()); nameView.setText(plugin.getName());
ImageButton logoView = (ImageButton)view.findViewById(R.id.plugin_logo); ImageButton logoView = (ImageButton)view.findViewById(R.id.plugin_logo);
logoView.setOnClickListener(toggleEnableDisableListener);
logoView.setImageResource(plugin.getLogoResourceId()); logoView.setImageResource(plugin.getLogoResourceId());
CompoundButton enableDisableButton = CompoundButton enableDisableButton =

View file

@ -26,7 +26,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
} }
@Override @Override
public boolean init(OsmandApplication app) { public boolean init(OsmandApplication app, Activity activity) {
return true; return true;
} }

View file

@ -98,7 +98,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
} }
@Override @Override
public boolean init(OsmandApplication app) { public boolean init(OsmandApplication app, Activity activity) {
return true; return true;
} }

View file

@ -74,7 +74,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
} }
@Override @Override
public boolean init(OsmandApplication app) { public boolean init(OsmandApplication app, Activity activity) {
settings = app.getSettings(); settings = app.getSettings();
return true; return true;
} }

View file

@ -0,0 +1,94 @@
package net.osmand.plus.openseamapsplugin;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.render.RendererRegistry;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
public class NauticalMapsPlugin extends OsmandPlugin {
public static final String ID = "nauticalPlugin.plugin";
public static final String COMPONENT = "net.osmand.nauticalPlugin";
private static String previousRenderer = RendererRegistry.DEFAULT_RENDER;
private OsmandApplication app;
public NauticalMapsPlugin(OsmandApplication app) {
this.app = app;
}
@Override
public String getDescription() {
return "Nautical Maps plugin provides detailed maps for sea and channels based on OSM data.\n "
+ "(Here could be description of provided details)\n"
+ "It changes default rendering style to 'nautical'. You can change it back in 'Configure Map' menu (Translation)";
}
@Override
public String getName() {
return app.getString(net.osmand.plus.R.string.plugin_nautical_name);
}
@Override
public boolean init(final OsmandApplication app, final Activity activity) {
if(activity != null) {
// called from UI
previousRenderer = app.getSettings().RENDERER.get();
app.getSettings().RENDERER.set(RendererRegistry.NAUTICAL_RENDER);
if(!app.getResourceManager().getIndexFileNames().containsKey("World_seamarks"+
"_" +IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_MAP_INDEX_EXT)){
Builder dlg = new AlertDialog.Builder(activity);
dlg.setMessage(net.osmand.plus.R.string.nautical_maps_missing);
dlg.setPositiveButton(R.string.default_buttons_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Intent intent = new Intent(activity, app.getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadActivity.FILTER_KEY, app.getString(net.osmand.plus.R.string.index_item_world_seamarks));
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
activity.startActivity(intent);
}
});
dlg.setNegativeButton(R.string.default_buttons_cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
app.getSettings().RENDERER.set(previousRenderer);
}
});
dlg.show();
}
}
return true;
}
@Override
public void disable(OsmandApplication app) {
super.disable(app);
if(app.getSettings().RENDERER.get().equals(RendererRegistry.NAUTICAL_RENDER)) {
app.getSettings().RENDERER.set(previousRenderer);
}
}
@Override
public String getId() {
return ID;
}
@Override
public Class<? extends Activity> getSettingsActivity() {
return null;
}
}

View file

@ -1,45 +0,0 @@
package net.osmand.plus.openseamapsplugin;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import android.app.Activity;
public class OpenSeaMapsPlugin extends OsmandPlugin {
public static final String ID = "openseamaps.plugin";
public static final String COMPONENT = "net.osmand.openseamapsPlugin";
private OsmandApplication app;
public OpenSeaMapsPlugin(OsmandApplication app) {
this.app = app;
}
@Override
public String getDescription() {
return "This will be a plugin enabling openseamaps (TODO)";
}
@Override
public String getName() {
return "Open Sea Maps";
}
@Override
public boolean init(final OsmandApplication app) {
return true;
}
@Override
public String getId() {
return ID;
}
@Override
public Class<? extends Activity> getSettingsActivity() {
return null;
}
}

View file

@ -52,7 +52,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
} }
@Override @Override
public boolean init(OsmandApplication app) { public boolean init(OsmandApplication app, Activity activity) {
settings = app.getSettings(); settings = app.getSettings();
return true; return true;
} }

View file

@ -79,7 +79,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
} }
@Override @Override
public boolean init(final OsmandApplication app) { public boolean init(final OsmandApplication app, Activity activity) {
if(app.getSettings().OSMO_AUTO_CONNECT.get() || if(app.getSettings().OSMO_AUTO_CONNECT.get() ||
(System.currentTimeMillis() - app.getSettings().OSMO_LAST_PING.get() < 5 * 60 * 1000 )) { (System.currentTimeMillis() - app.getSettings().OSMO_LAST_PING.get() < 5 * 60 * 1000 )) {
service.connect(true); service.connect(true);

View file

@ -146,7 +146,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
@Override @Override
public boolean init(OsmandApplication app) { public boolean init(OsmandApplication app, Activity activity) {
return true; return true;
} }

View file

@ -58,7 +58,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
} }
@Override @Override
public boolean init(OsmandApplication app) { public boolean init(OsmandApplication app, Activity activity) {
settings = app.getSettings(); settings = app.getSettings();
return true; return true;
} }

View file

@ -24,6 +24,9 @@ public class RendererRegistry {
private final static Log log = PlatformUtil.getLog(RendererRegistry.class); private final static Log log = PlatformUtil.getLog(RendererRegistry.class);
public final static String DEFAULT_RENDER = "OsmAnd"; //$NON-NLS-1$ public final static String DEFAULT_RENDER = "OsmAnd"; //$NON-NLS-1$
public final static String NAUTICAL_RENDER = "Nautical"; //$NON-NLS-1$
public static final String WINTER_SKI_RENDER = "Winter-and-ski";
private RenderingRulesStorage defaultRender = null; private RenderingRulesStorage defaultRender = null;
private RenderingRulesStorage currentSelectedRender = null; private RenderingRulesStorage currentSelectedRender = null;
@ -45,8 +48,8 @@ public class RendererRegistry {
internalRenderers.put("UniRS", "UniRS" + ".render.xml"); internalRenderers.put("UniRS", "UniRS" + ".render.xml");
internalRenderers.put("LightRS", "LightRS" + ".render.xml"); internalRenderers.put("LightRS", "LightRS" + ".render.xml");
internalRenderers.put("High-contrast-roads", "High-contrast-roads" + ".render.xml"); internalRenderers.put("High-contrast-roads", "High-contrast-roads" + ".render.xml");
internalRenderers.put("Winter-and-ski", "Winter-and-ski" + ".render.xml"); internalRenderers.put(WINTER_SKI_RENDER, "Winter-and-ski" + ".render.xml");
internalRenderers.put("Nautical", "nautical" + ".render.xml"); internalRenderers.put(NAUTICAL_RENDER, "nautical" + ".render.xml");
} }
public RenderingRulesStorage defaultRender() { public RenderingRulesStorage defaultRender() {

View file

@ -169,7 +169,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
} }
@Override @Override
public boolean init(OsmandApplication app) { public boolean init(OsmandApplication app, Activity activity) {
return true; return true;
} }

View file

@ -1,14 +1,23 @@
package net.osmand.plus.skimapsplugin; package net.osmand.plus.skimapsplugin;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.render.RendererRegistry;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
public class SkiMapsPlugin extends OsmandPlugin { public class SkiMapsPlugin extends OsmandPlugin {
public static final String ID = "skimaps.plugin"; public static final String ID = "skimaps.plugin";
public static final String COMPONENT = "net.osmand.skimapsPlugin"; public static final String COMPONENT = "net.osmand.skimapsPlugin";
private OsmandApplication app; private OsmandApplication app;
private String previousRenderer = RendererRegistry.DEFAULT_RENDER;
public SkiMapsPlugin(OsmandApplication app) { public SkiMapsPlugin(OsmandApplication app) {
this.app = app; this.app = app;
@ -16,18 +25,56 @@ public class SkiMapsPlugin extends OsmandPlugin {
@Override @Override
public String getDescription() { public String getDescription() {
return "This will be a plugin enabling ski maps (TODO)"; return "Nautical Maps plugin provides maps for pistes based on OSM data.\n "
+ "(Here could be description of provided details)\n"
+ "It changes default rendering style to 'Winter-Ski'. You can change it back in 'Configure Map' menu (Translation)";
} }
@Override @Override
public String getName() { public String getName() {
return "Ski Maps"; return app.getString(net.osmand.plus.R.string.plugin_ski_name);
} }
@Override @Override
public boolean init(final OsmandApplication app) { public boolean init(final OsmandApplication app, final Activity activity) {
if(activity != null) {
// called from UI
previousRenderer = app.getSettings().RENDERER.get();
app.getSettings().RENDERER.set(RendererRegistry.WINTER_SKI_RENDER);
if(!app.getResourceManager().getIndexFileNames().containsKey("World-ski"+
"_" +IndexConstants.BINARY_MAP_VERSION + IndexConstants.BINARY_MAP_INDEX_EXT)){
Builder dlg = new AlertDialog.Builder(activity);
dlg.setMessage(net.osmand.plus.R.string.world_ski_missing);
dlg.setPositiveButton(net.osmand.plus.R.string.default_buttons_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Intent intent = new Intent(activity, app.getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadActivity.FILTER_KEY, app.getString(net.osmand.plus.R.string.index_item_world_ski));
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
activity.startActivity(intent);
}
});
dlg.setNegativeButton(net.osmand.plus.R.string.default_buttons_cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
app.getSettings().RENDERER.set(previousRenderer);
}
});
dlg.show();
}
}
return true; return true;
} }
@Override
public void disable(OsmandApplication app) {
super.disable(app);
if(app.getSettings().RENDERER.get().equals(RendererRegistry.WINTER_SKI_RENDER)) {
app.getSettings().RENDERER.set(previousRenderer);
}
}
@Override @Override

View file

@ -43,7 +43,7 @@ public class SRTMPlugin extends OsmandPlugin {
} }
@Override @Override
public boolean init(final OsmandApplication app) { public boolean init(final OsmandApplication app, Activity activity) {
HILLSHADE = app.getSettings().registerBooleanPreference("hillshade_layer", true); HILLSHADE = app.getSettings().registerBooleanPreference("hillshade_layer", true);
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
CommonPreference<String> pref = settings.getCustomRenderProperty("contourLines"); CommonPreference<String> pref = settings.getCustomRenderProperty("contourLines");