Add plugins screen
This commit is contained in:
parent
4846c6f647
commit
b3ff63b573
10 changed files with 156 additions and 8 deletions
|
@ -43,6 +43,7 @@
|
|||
<activity android:name="net.osmand.plus.activities.ShowRouteInfoActivity" android:label="@string/show_route"></activity>
|
||||
<activity android:name="net.osmand.plus.activities.FavouritesListActivity"></activity>
|
||||
<activity android:name="net.osmand.plus.activities.FavouritesActivity"></activity>
|
||||
<activity android:name="net.osmand.plus.activities.PluginsActivity"></activity>
|
||||
<activity android:name="net.osmand.plus.activities.ContributionVersionActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/contribution_activity"></activity>
|
||||
|
||||
|
||||
|
|
13
OsmAnd/res/layout/plugins.xml
Normal file
13
OsmAnd/res/layout/plugins.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" android:orientation="vertical">
|
||||
|
||||
<TextView android:id="@+id/Label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/select_plugin_to_activate"></TextView>
|
||||
|
||||
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="3dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp" style="@style/OsmandListView"></ListView>
|
||||
<Button android:id="@+id/DownloadButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/download_files"
|
||||
android:layout_marginLeft = "3dp" android:layout_marginTop ="3dp" android:layout_marginRight = "3dp" android:visibility="gone"/>
|
||||
</LinearLayout>
|
14
OsmAnd/res/layout/plugins_list_item.xml
Normal file
14
OsmAnd/res/layout/plugins_list_item.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<ImageView android:id="@+id/plugin_icon" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
|
||||
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"
|
||||
android:layout_marginLeft="3dp" >
|
||||
<TextView android:id="@+id/plugin_name" android:gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:textSize="17sp"></TextView>
|
||||
|
||||
<TextView android:id="@+id/plugin_descr" android:gravity="center_horizontal" android:layout_width="fill_parent"
|
||||
android:maxLines="5" android:layout_height="wrap_content" android:textSize="15sp" ></TextView>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -1,5 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="plugins_screen">Plugins</string>
|
||||
<string name="select_plugin_to_activate">Touch a plugin item to activate it. Application restart is needed to take an effect.</string>
|
||||
<string name="prefs_plugins_descr">Plugins enable extra functionality builtin in the application such as Tracking, Tile Maps, Battery Saving features, Accessibility and many others.</string>
|
||||
<string name="prefs_plugins">Plugins</string>
|
||||
<string name="tip_recent_changes_0_8_0_t">Changes in 0.8.0 :
|
||||
\n\t- Plugin functionality
|
||||
\n\t- New offline map data support
|
||||
|
|
|
@ -120,6 +120,8 @@
|
|||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
||||
<Preference android:title="@string/prefs_plugins" android:summary="@string/prefs_plugins_descr" android:key="plugins"/>
|
||||
|
||||
<PreferenceScreen android:title="@string/osmand_service" android:summary="@string/osmand_service_descr">
|
||||
<CheckBoxPreference android:summary="@string/background_router_service_descr" android:title="@string/background_router_service"
|
||||
android:key="service_off_enabled"></CheckBoxPreference>
|
||||
|
|
|
@ -60,6 +60,7 @@ public class ContextMenuAdapter {
|
|||
itemNames.add(pos, ctx.getString(stringResId));
|
||||
selectedList.insert(pos, selected);
|
||||
iconList.insert(pos, icon);
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void registerSelectedItem(int stringResId, int selected, int icon) {
|
||||
|
|
|
@ -5,6 +5,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -13,9 +16,7 @@ public abstract class OsmandPlugin {
|
|||
|
||||
private static List<OsmandPlugin> installedPlugins = new ArrayList<OsmandPlugin>();
|
||||
private static List<OsmandPlugin> activePlugins = new ArrayList<OsmandPlugin>();
|
||||
static {
|
||||
installedPlugins.add(new OsmEditingPlugin());
|
||||
}
|
||||
private static final Log LOG = LogUtil.getLog(OsmandPlugin.class);
|
||||
|
||||
|
||||
public abstract String getId();
|
||||
|
@ -36,12 +37,17 @@ public abstract class OsmandPlugin {
|
|||
|
||||
public static void initPlugins(OsmandApplication app) {
|
||||
OsmandSettings settings = app.getSettings();
|
||||
installedPlugins.add(new OsmEditingPlugin(app));
|
||||
Set<String> enabledPlugins = settings.getEnabledPlugins();
|
||||
for (OsmandPlugin plugin : installedPlugins) {
|
||||
if (enabledPlugins.contains(plugin.getId())) {
|
||||
try {
|
||||
if (plugin.init(app)) {
|
||||
activePlugins.add(plugin);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Plugin initialization failed " + plugin.getId(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
100
OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java
Normal file
100
OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java
Normal file
|
@ -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<OsmandPlugin> availablePlugins;
|
||||
private Set<String> enabledPlugins = new LinkedHashSet<String>();
|
||||
private Set<String> restartPlugins = new LinkedHashSet<String>();
|
||||
|
||||
@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<OsmandPlugin> 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<OsmandPlugin> {
|
||||
|
||||
public OsmandPluginsAdapter(List<OsmandPlugin> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue