diff --git a/astrid/res/layout/billing_activity.xml b/astrid/res/layout/billing_activity.xml
new file mode 100644
index 000000000..f1c9ddb86
--- /dev/null
+++ b/astrid/res/layout/billing_activity.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/astrid/res/values/strings-premium.xml b/astrid/res/values/strings-premium.xml
index b27baab61..89f15f1c4 100644
--- a/astrid/res/values/strings-premium.xml
+++ b/astrid/res/values/strings-premium.xml
@@ -44,4 +44,12 @@
Error copying file for attachmentError downloading fileSorry, the system does not yet support this type of file
+
+
+ Subscriptions not supported
+ Sorry! The Market billing
+ service on this device does not support subscriptions at this time.
+ Learn more
+ http://market.android.com/support/bin/answer.py?answer=1050566&hl=%lang%&dl=%region%
+
diff --git a/astrid/src/com/todoroo/astrid/billing/BillingActivity.java b/astrid/src/com/todoroo/astrid/billing/BillingActivity.java
new file mode 100644
index 000000000..7b69811e3
--- /dev/null
+++ b/astrid/src/com/todoroo/astrid/billing/BillingActivity.java
@@ -0,0 +1,99 @@
+package com.todoroo.astrid.billing;
+
+import java.util.Locale;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+import com.timsu.astrid.R;
+
+public class BillingActivity extends Activity {
+
+ private BillingService billingService;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.billing_activity);
+
+ setupButtons();
+
+ billingService = new BillingService();
+ billingService.setContext(this);
+
+ if (!billingService.checkBillingSupported(BillingConstants.ITEM_TYPE_SUBSCRIPTION)) {
+ showSubscriptionsNotSupported();
+ }
+ }
+
+ private void setupButtons() {
+ Button buyMonth = (Button) findViewById(R.id.buy_month);
+ Button buyYear = (Button) findViewById(R.id.buy_year);
+
+ //TODO: Figure out if we need a payload for any reason
+
+ buyMonth.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (!billingService.requestPurchase(BillingConstants.PRODUCT_ID_MONTHLY,
+ BillingConstants.ITEM_TYPE_SUBSCRIPTION, null)) {
+ showSubscriptionsNotSupported();
+ }
+ }
+ });
+
+ buyYear.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (!billingService.requestPurchase(BillingConstants.PRODUCT_ID_YEARLY,
+ BillingConstants.ITEM_TYPE_SUBSCRIPTION, null)) {
+ showSubscriptionsNotSupported();
+ }
+ }
+ });
+ }
+
+ private void showSubscriptionsNotSupported() {
+ String helpUrl = replaceLanguageAndRegion(getString(R.string.subscriptions_help_url));
+ final Uri helpUri = Uri.parse(helpUrl);
+
+ new AlertDialog.Builder(this)
+ .setTitle(R.string.subscriptions_not_supported)
+ .setMessage(R.string.subscriptions_not_supported_message)
+ .setCancelable(false)
+ .setPositiveButton(R.string.DLG_ok, null)
+ .setNegativeButton(R.string.subscriptions_learn_more, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Intent intent = new Intent(Intent.ACTION_VIEW, helpUri);
+ startActivity(intent);
+ }
+ }).create().show();
+ }
+
+ /**
+ * Replaces the language and/or country of the device into the given string.
+ * The pattern "%lang%" will be replaced by the device's language code and
+ * the pattern "%region%" will be replaced with the device's country code.
+ *
+ * @param str the string to replace the language/country within
+ * @return a string containing the local language and region codes
+ */
+ @SuppressWarnings("nls")
+ private String replaceLanguageAndRegion(String str) {
+ // Substitute language and or region if present in string
+ if (str.contains("%lang%") || str.contains("%region%")) {
+ Locale locale = Locale.getDefault();
+ str = str.replace("%lang%", locale.getLanguage().toLowerCase());
+ str = str.replace("%region%", locale.getCountry().toLowerCase());
+ }
+ return str;
+ }
+}
diff --git a/astrid/src/com/todoroo/astrid/billing/BillingConstants.java b/astrid/src/com/todoroo/astrid/billing/BillingConstants.java
index 06c0c3b3e..9be884899 100644
--- a/astrid/src/com/todoroo/astrid/billing/BillingConstants.java
+++ b/astrid/src/com/todoroo/astrid/billing/BillingConstants.java
@@ -53,6 +53,10 @@ public class BillingConstants {
public static final String ITEM_TYPE_SUBSCRIPTION = "subs";
+
+ public static final String PRODUCT_ID_MONTHLY = "premium_monthly";
+ public static final String PRODUCT_ID_YEARLY = "premium_yearly";
+
// The response codes for a request, defined by Android Market.
public enum ResponseCode {
RESULT_OK,