From 28067d440b880e46e5773f3939bb782e8d3fb718 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Wed, 14 Mar 2012 17:04:06 -0700 Subject: [PATCH] Instead of disabling or enabling market strategy, create a mechanism to swap different markets. --- astrid/build.xml | 10 +-- .../astrid/activity/TaskListFragment.java | 5 +- .../todoroo/astrid/adapter/AddOnAdapter.java | 5 +- .../todoroo/astrid/service/AddOnService.java | 26 ++++---- .../astrid/service/MarketStrategy.java | 62 +++++++++++++++++++ .../astrid/service/StartupService.java | 7 ++- .../com/todoroo/astrid/utility/Constants.java | 6 +- .../astrid/voice/VoiceInputAssistant.java | 5 +- build.xml | 2 +- 9 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 astrid/src/com/todoroo/astrid/service/MarketStrategy.java diff --git a/astrid/build.xml b/astrid/build.xml index 77bf47dbc..47da849f1 100644 --- a/astrid/build.xml +++ b/astrid/build.xml @@ -59,7 +59,7 @@ message="Cannot run two different modes at the same time. If you are running more than one debug/release/instrument type targets, call them from different Ant calls." /> - + @@ -158,13 +158,13 @@ - - + + + match="AndroidMarketStrategy" + replace="${custom.market.strategy}" /> list = new ArrayList(3); + if(Constants.MARKET_STRATEGY.includesPowerPack()) + list.add(new AddOn(false, true, "Astrid Power Pack", null, "Support Astrid and get more productive with the Astrid Power Pack. 4x2 and 4x4 widgets and voice integration. Power up today!", POWER_PACK_PACKAGE, "http://www.weloveastrid.com/store", - ((BitmapDrawable)r.getDrawable(R.drawable.icon_pp)).getBitmap()); + ((BitmapDrawable)r.getDrawable(R.drawable.icon_pp)).getBitmap())); - list[1] = new AddOn(false, true, "Astrid Locale Plugin", null, + if(Constants.MARKET_STRATEGY.includesLocalePlugin()) + list.add(new AddOn(false, true, "Astrid Locale Plugin", null, "Allows Astrid to make use of the Locale application to send you notifications based on filter conditions. Requires Locale.", LOCALE_PACKAGE, "http://www.weloveastrid.com/store", - ((BitmapDrawable)r.getDrawable(R.drawable.icon_locale)).getBitmap()); + ((BitmapDrawable)r.getDrawable(R.drawable.icon_locale)).getBitmap())); - list[2] = new AddOn(true, true, "Producteev", null, + list.add(new AddOn(true, true, "Producteev", null, "Synchronize with Producteev service. Also changes Astrid's importance levels to stars.", Constants.PACKAGE, "http://www.producteev.com", - ((BitmapDrawable)r.getDrawable(R.drawable.icon_producteev)).getBitmap()); + ((BitmapDrawable)r.getDrawable(R.drawable.icon_producteev)).getBitmap())); - return list; + return list.toArray(new AddOn[list.size()]); } } diff --git a/astrid/src/com/todoroo/astrid/service/MarketStrategy.java b/astrid/src/com/todoroo/astrid/service/MarketStrategy.java new file mode 100644 index 000000000..816e1b02c --- /dev/null +++ b/astrid/src/com/todoroo/astrid/service/MarketStrategy.java @@ -0,0 +1,62 @@ +package com.todoroo.astrid.service; + +import android.content.Intent; +import android.net.Uri; + +public abstract class MarketStrategy { + + /** + * @param packageName + * @return an intent to launch market with this package + */ + abstract public Intent generateMarketLink(String packageName); + + /** + * @return if this market has power pack + */ + public boolean includesPowerPack() { + return true; + } + + /** + * @return if this market has locale plugin + */ + public boolean includesLocalePlugin() { + return true; + } + + /** + * @return true if addons should be shown + */ + public boolean showAddonMenu() { + return true; + } + + public static class AndroidMarketStrategy extends MarketStrategy { + + @Override + public Intent generateMarketLink(String packageName) { + return new Intent(Intent.ACTION_VIEW, + Uri.parse("market://search?q=pname:" + //$NON-NLS-1$ + packageName)); + } + + } + + public static class AmazonMarketStrategy extends MarketStrategy { + + @Override + public Intent generateMarketLink(String packageName) { + return new Intent(Intent.ACTION_VIEW, + Uri.parse("http://www.amazon.com/gp/mas/dl/android?p=" + //$NON-NLS-1$ + packageName)); + } + + @Override + public boolean includesLocalePlugin() { + return false; + } + + } + +} diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index 8213b907b..bc28aef17 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -110,7 +110,8 @@ public class StartupService { if(!StatisticsService.dontCollectStatistics()) { Crittercism.init(context.getApplicationContext(), Constants.CRITTERCISM_APP_ID); - Crittercism.setShouldUseAmazonMarket(Constants.MARKET_DISABLED); + Crittercism.setShouldUseAmazonMarket(Constants.MARKET_STRATEGY.getClass() == + MarketStrategy.AmazonMarketStrategy.class); } try { @@ -217,6 +218,10 @@ public class StartupService { hasStartedUp = true; } + /** + * @param context + * @param e error that was raised + */ public static void handleSQLiteColumnMissing(Context context, final SQLiteException e) { new AlertDialog.Builder(context) .setTitle(R.string.DB_corrupted_title) diff --git a/astrid/src/com/todoroo/astrid/utility/Constants.java b/astrid/src/com/todoroo/astrid/utility/Constants.java index 420213b87..a41431af5 100644 --- a/astrid/src/com/todoroo/astrid/utility/Constants.java +++ b/astrid/src/com/todoroo/astrid/utility/Constants.java @@ -1,5 +1,7 @@ package com.todoroo.astrid.utility; +import com.todoroo.astrid.service.MarketStrategy; + @SuppressWarnings("nls") public final class Constants { @@ -21,9 +23,9 @@ public final class Constants { public static final boolean OEM = false; /** - * Whether this is an Android Market-disabled build + * Market selection strategy */ - public static final boolean MARKET_DISABLED = false; + public static final MarketStrategy MARKET_STRATEGY = new MarketStrategy.AndroidMarketStrategy(); /** * Interval to update the widget (in order to detect hidden tasks diff --git a/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java b/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java index 183aa6a06..b7ac7edc0 100644 --- a/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java +++ b/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java @@ -11,7 +11,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.net.Uri; import android.speech.RecognizerIntent; import android.support.v4.app.Fragment; import android.util.Log; @@ -25,6 +24,7 @@ import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.Preferences; +import com.todoroo.astrid.utility.Constants; /** * This class handles taking voice-input and appends the text to the registered EditText-instance. @@ -312,8 +312,7 @@ public class VoiceInputAssistant { packageName = "com.google.android.voicesearch"; // User wants to install voice search, take them to the market - Intent marketIntent = new Intent(Intent.ACTION_VIEW, - Uri.parse("market://search?q=pname:" + packageName)); //$NON-NLS-1$ + Intent marketIntent = Constants.MARKET_STRATEGY.generateMarketLink(packageName); if (activity != null) { try { activity.startActivity(marketIntent); diff --git a/build.xml b/build.xml index ce7fd0330..272da0eec 100644 --- a/build.xml +++ b/build.xml @@ -48,7 +48,7 @@ - +