From 6df07b2c2d87a227b165ea2df40008a68c19c151 Mon Sep 17 00:00:00 2001 From: aFedasenka Date: Sun, 8 Jul 2012 20:22:30 +0200 Subject: [PATCH] Parking plugin is visible and enabled only when ParkingPlugin component is installed. --- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 23 ++++++++++++++++++- .../parkingPlugin/ParkingPluginActivity.java | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 4aca31e008..0417ce417c 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -20,6 +20,10 @@ import net.osmand.plus.views.OsmandMapTileView; import org.apache.commons.logging.Log; +import android.content.ComponentName; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.preference.PreferenceScreen; import android.view.Menu; @@ -29,6 +33,9 @@ public abstract class OsmandPlugin { private static List activePlugins = new ArrayList(); private static final Log LOG = LogUtil.getLog(OsmandPlugin.class); + private static final String PARKING_PLUGIN_COMPONENT = "net.osmand.parkingPlugin"; //$NON-NLS-1$ + private static final String PARKING_PLUGIN_ACTIVITY = "net.osmand.parkingPlugin.ParkingPluginActivity"; //$NON-NLS-1$ + public abstract String getId(); @@ -58,7 +65,8 @@ public abstract class OsmandPlugin { installedPlugins.add(new AccessibilityPlugin(app)); installedPlugins.add(new OsmEditingPlugin(app)); installedPlugins.add(new OsmandDevelopmentPlugin(app)); - installedPlugins.add(new ParkingPositionPlugin(app)); +// installedPlugins.add(parkingPlugin); + installParkingPlugin(app); Set enabledPlugins = settings.getEnabledPlugins(); for (OsmandPlugin plugin : installedPlugins) { @@ -223,4 +231,17 @@ public abstract class OsmandPlugin { return false; } + private static void installParkingPlugin(OsmandApplication app) { + Intent parkingIntent = new Intent(); + parkingIntent.setComponent(new ComponentName(PARKING_PLUGIN_COMPONENT, PARKING_PLUGIN_ACTIVITY)); + parkingIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + ResolveInfo resolved = app.getPackageManager().resolveActivity(parkingIntent, PackageManager.MATCH_DEFAULT_ONLY); + ParkingPositionPlugin parkingPlugin = new ParkingPositionPlugin(app); + if(resolved != null) { + installedPlugins.add(parkingPlugin); + app.getSettings().enablePlugin(parkingPlugin.getId(), true); + } else { + app.getSettings().enablePlugin(parkingPlugin.getId(), false); + } + } } diff --git a/plugins/Osmand-ParkingPlugin/src/net/osmand/parkingPlugin/ParkingPluginActivity.java b/plugins/Osmand-ParkingPlugin/src/net/osmand/parkingPlugin/ParkingPluginActivity.java index 3c36d9d57e..2eccccfe78 100644 --- a/plugins/Osmand-ParkingPlugin/src/net/osmand/parkingPlugin/ParkingPluginActivity.java +++ b/plugins/Osmand-ParkingPlugin/src/net/osmand/parkingPlugin/ParkingPluginActivity.java @@ -27,6 +27,7 @@ public class ParkingPluginActivity extends Activity { intentPlus.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); ResolveInfo resolved = getPackageManager().resolveActivity(intentPlus, PackageManager.MATCH_DEFAULT_ONLY); if(resolved != null) { + stopService(intentPlus); startActivity(intentPlus); } else { Intent intentNormal = new Intent(); @@ -34,6 +35,7 @@ public class ParkingPluginActivity extends Activity { intentNormal.setComponent(new ComponentName(OSMAND_COMPONENT, OSMAND_ACTIVITY)); resolved = getPackageManager().resolveActivity(intentNormal, PackageManager.MATCH_DEFAULT_ONLY); if (resolved != null) { + stopService(intentNormal); startActivity(intentNormal); } else { AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -43,6 +45,7 @@ public class ParkingPluginActivity extends Activity { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + OSMAND_COMPONENT_PLUS)); try { + stopService(intent); startActivity(intent); } catch (ActivityNotFoundException e) { }