diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml
index f0077c5b32..c30ebc27ce 100644
--- a/OsmAnd/AndroidManifest.xml
+++ b/OsmAnd/AndroidManifest.xml
@@ -43,6 +43,7 @@
+
diff --git a/OsmAnd/res/layout/plugins.xml b/OsmAnd/res/layout/plugins.xml
new file mode 100644
index 0000000000..7c391def84
--- /dev/null
+++ b/OsmAnd/res/layout/plugins.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
diff --git a/OsmAnd/res/layout/plugins_list_item.xml b/OsmAnd/res/layout/plugins_list_item.xml
new file mode 100644
index 0000000000..07ba480023
--- /dev/null
+++ b/OsmAnd/res/layout/plugins_list_item.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 6dd592ffc7..d8c6bb1893 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -1,5 +1,9 @@
+ Plugins
+ Touch a plugin item to activate it. Application restart is needed to take an effect.
+ Plugins enable extra functionality builtin in the application such as Tracking, Tile Maps, Battery Saving features, Accessibility and many others.
+ Plugins
Changes in 0.8.0 :
\n\t- Plugin functionality
\n\t- New offline map data support
diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml
index 540531af36..45d13407e7 100644
--- a/OsmAnd/res/xml/settings_pref.xml
+++ b/OsmAnd/res/xml/settings_pref.xml
@@ -119,6 +119,8 @@
+
+
installedPlugins = new ArrayList();
private static List activePlugins = new ArrayList();
- static {
- installedPlugins.add(new OsmEditingPlugin());
- }
+ private static final Log LOG = LogUtil.getLog(OsmandPlugin.class);
public abstract String getId();
@@ -36,11 +37,16 @@ public abstract class OsmandPlugin {
public static void initPlugins(OsmandApplication app) {
OsmandSettings settings = app.getSettings();
+ installedPlugins.add(new OsmEditingPlugin(app));
Set enabledPlugins = settings.getEnabledPlugins();
for (OsmandPlugin plugin : installedPlugins) {
if (enabledPlugins.contains(plugin.getId())) {
- if (plugin.init(app)) {
- activePlugins.add(plugin);
+ try {
+ if (plugin.init(app)) {
+ activePlugins.add(plugin);
+ }
+ } catch (Exception e) {
+ LOG.error("Plugin initialization failed " + plugin.getId(), e);
}
}
}
diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java b/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java
new file mode 100644
index 0000000000..bd5b313890
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java
@@ -0,0 +1,100 @@
+package net.osmand.plus.activities;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.OsmandPlugin;
+import net.osmand.plus.R;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+
+public class PluginsActivity extends OsmandListActivity {
+
+ private List availablePlugins;
+ private Set enabledPlugins = new LinkedHashSet();
+ private Set restartPlugins = new LinkedHashSet();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ CustomTitleBar titleBar = new CustomTitleBar(this, R.string.plugins_screen, R.drawable.tab_favorites_screen_icon);
+ setContentView(R.layout.plugins);
+
+ availablePlugins = OsmandPlugin.getAvailablePlugins();
+ List enabledPlugins = OsmandPlugin.getEnabledPlugins();
+ for(OsmandPlugin p : enabledPlugins) {
+ restartPlugins.add(p.getId());
+ this.enabledPlugins.add(p.getId());
+ }
+
+ titleBar.afterSetContentView();
+ setListAdapter(new OsmandPluginsAdapter(availablePlugins));
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+ super.onListItemClick(l, v, position, id);
+ OsmandPlugin item = getListAdapter().getItem(position);
+ boolean enable = true;
+ if(restartPlugins.contains(item.getId())) {
+ restartPlugins.remove(item.getId());
+ enable = false;
+ } else {
+ restartPlugins.add(item.getId());
+ }
+ ((OsmandApplication) getApplication()).getSettings().enablePlugin(item.getId(), enable);
+ getListAdapter().notifyDataSetInvalidated();
+ }
+
+ @Override
+ public OsmandPluginsAdapter getListAdapter() {
+ return (OsmandPluginsAdapter) super.getListAdapter();
+ }
+
+ private int colorGreen = 0xff23CC6C;
+ protected class OsmandPluginsAdapter extends ArrayAdapter {
+
+ public OsmandPluginsAdapter(List plugins) {
+ super(PluginsActivity.this, R.layout.plugins_list_item, plugins);
+ }
+
+ @Override
+ public View getView(final int position, View convertView, ViewGroup parent) {
+ View v = convertView;
+ if (v == null) {
+ LayoutInflater inflater = getLayoutInflater();
+ v = inflater.inflate(net.osmand.plus.R.layout.plugins_list_item, parent, false);
+ }
+ final View row = v;
+ OsmandPlugin plugin = getItem(position);
+ ImageView imgView = (ImageView) row.findViewById(R.id.plugin_icon);
+ imgView.setImageDrawable(getResources().getDrawable(R.drawable.icon_small));
+ TextView nameView = (TextView) row.findViewById(R.id.plugin_name);
+ nameView.setText(plugin.getName());
+
+ TextView description = (TextView) row.findViewById(R.id.plugin_descr);
+ description.setText(plugin.getDescription());
+ boolean enabled = enabledPlugins.contains(plugin.getId());
+ boolean toBeEnabled = restartPlugins.contains(plugin.getId());
+ description.setTextColor(toBeEnabled? colorGreen : Color.GRAY);
+ nameView.setTextColor(toBeEnabled? colorGreen : Color.GRAY);
+ description.setTypeface(enabled? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
+ nameView.setTypeface(enabled? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
+
+ return row;
+ }
+
+ }
+
+
+}
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
index ab599d1f70..94f79b77c8 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
@@ -58,8 +58,6 @@ import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
-import android.util.AttributeSet;
-import android.view.View;
import android.widget.Toast;
public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnPreferenceClickListener {
@@ -75,6 +73,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private Preference testVoiceCommands;
private Preference localOpenstreetmapPoints;
private Preference bidforfix;
+ private Preference plugins;
private EditTextPreference applicationDir;
private ListPreference applicationModePreference;
@@ -379,6 +378,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
localOpenstreetmapPoints.setOnPreferenceClickListener(this);
bidforfix = (Preference) screen.findPreference("bidforfix");
bidforfix.setOnPreferenceClickListener(this);
+ plugins = (Preference) screen.findPreference("plugins");
+ plugins.setOnPreferenceClickListener(this);
broadcastReceiver = new BroadcastReceiver(){
@Override
@@ -865,6 +866,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} else if(preference == bidforfix){
startActivity(new Intent(this, OsmandBidForFixActivity.class));
return true;
+ } else if(preference == plugins){
+ startActivity(new Intent(this, PluginsActivity.class));
+ return true;
}
return false;
}
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
index e04711d882..a33dcdd9c8 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java
@@ -20,9 +20,12 @@ public class OsmEditingPlugin extends OsmandPlugin {
return ID;
}
+ public OsmEditingPlugin(OsmandApplication app) {
+ this.app = app;
+ }
+
@Override
public boolean init(OsmandApplication app) {
- this.app = app;
settings = app.getSettings();
return true;
}