Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved configuration to Application subclass and refactored auxiliary …

…classes to their own package.
  • Loading branch information...
commit d4e3cb2f52605f0dcf9ae1d899760f0a72950823 1 parent da7206a
Robot Media authored
View
2  DungeonsRedux/AndroidManifest.xml
@@ -6,7 +6,7 @@
<!-- Add this permission to your manifest -->
<uses-permission android:name="com.android.vending.BILLING" />
- <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <application android:icon="@drawable/icon" android:label="@string/app_name" android:name=".Application">
<activity android:name=".Dungeons" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
View
12 DungeonsRedux/README
@@ -1,8 +1,8 @@
-This package contains a sample app -Dungeons Redux- that shows how to use the Android Billing
-Library (https://github.com/robotmedia/AndroidBillingLibrary). It does not intend to be an
-example of how to use in-app billing in general.
+Dungeons Redux is a sample app that shows how to use the Android Billing Library by Robot Media.
+It is a simplified version of the Dungeons in-app billing sample app provided by Google.
-Dungeons Redux is a simplified version of the Dungeons sample app provided by Google.
+Dungeons Redux does not intend to be an example of how to use in-app billing in general, just
+Android Billing Library.
-------------------------------------
Configuring the sample application
@@ -17,13 +17,13 @@ code, do the following:
2. On the upper left part of the page, under your name, click Edit Profile.
3. On the Edit Profile page, scroll down to the Licensing & In-app Billing panel.
4. Copy your public key to the clipboard.
-5. Open src/net/robotmedia/billing/example/Dungeons.java in the editor of your choice.
+5. Open src/net/robotmedia/billing/example/Application.java in the editor of your choice.
6. Search for the following line:
return "your public key here";
7. Replace the string with your public key.
8. Save the file.
-After you add your public key to the Dungeons.java file, you can compile the application as you
+After you add your public key to the Application.java file, you can compile the application as you
normally would.
-------------------------------------
View
25 DungeonsRedux/src/net/robotmedia/billing/example/Application.java
@@ -0,0 +1,25 @@
+package net.robotmedia.billing.example;
+
+import net.robotmedia.billing.BillingController;
+
+public class Application extends android.app.Application {
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ BillingController.setDebug(true);
+ BillingController.setConfiguration(new BillingController.IConfiguration() {
+
+ @Override
+ public byte[] getObfuscationSalt() {
+ return new byte[] {41, -90, -116, -41, 66, -53, 122, -110, -127, -96, -88, 77, 127, 115, 1, 73, 57, 110, 48, -116};
+ }
+
+ @Override
+ public String getPublicKey() {
+ return "your public key here";
+ }
+ });
+ }
+
+}
View
28 DungeonsRedux/src/net/robotmedia/billing/example/CatalogEntry.java
@@ -1,28 +0,0 @@
-package net.robotmedia.billing.example;
-
-public class CatalogEntry {
-
- /**
- * Each product in the catalog is either MANAGED or UNMANAGED. MANAGED means
- * that the product can be purchased only once per user (such as a new level
- * in a game). The purchase is remembered by Android Market and can be
- * restored if this application is uninstalled and then re-installed.
- * UNMANAGED is used for products that can be used up and purchased multiple
- * times (such as poker chips). It is up to the application to keep track of
- * UNMANAGED products for the user.
- */
- public enum Managed {
- MANAGED, UNMANAGED
- }
-
- public String sku;
- public int nameId;
- public Managed managed;
-
- public CatalogEntry(String sku, int nameId, Managed managed) {
- this.sku = sku;
- this.nameId = nameId;
- this.managed = managed;
- }
-
-}
View
33 DungeonsRedux/src/net/robotmedia/billing/example/Dungeons.java
@@ -24,9 +24,9 @@
import net.robotmedia.billing.BillingController;
import net.robotmedia.billing.IBillingObserver;
-import net.robotmedia.billing.BillingController.IConfiguration;
import net.robotmedia.billing.example.R;
-import net.robotmedia.billing.example.CatalogEntry.Managed;
+import net.robotmedia.billing.example.aux.CatalogAdapter;
+import net.robotmedia.billing.example.aux.CatalogEntry;
import net.robotmedia.billing.model.Transaction;
import net.robotmedia.billing.model.Transaction.PurchaseState;
@@ -34,7 +34,7 @@
* A sample application based on the original Dungeons to demonstrate how to use
* BillingController and implement IBillingObserver.
*/
-public class Dungeons extends Activity implements IBillingObserver, IConfiguration {
+public class Dungeons extends Activity implements IBillingObserver {
private static final String TAG = "Dungeons";
@@ -50,14 +50,6 @@
private static final int DIALOG_BILLING_NOT_SUPPORTED_ID = 2;
- /** An array of product list entries for the products that can be purchased. */
- private static final CatalogEntry[] CATALOG = new CatalogEntry[] {
- new CatalogEntry("sword_001", R.string.two_handed_sword, Managed.MANAGED),
- new CatalogEntry("potion_001", R.string.potions, Managed.UNMANAGED),
- new CatalogEntry("android.test.purchased", R.string.android_test_purchased, Managed.UNMANAGED),
- new CatalogEntry("android.test.canceled", R.string.android_test_canceled, Managed.UNMANAGED),
- new CatalogEntry("android.test.refunded", R.string.android_test_refunded, Managed.UNMANAGED),
- new CatalogEntry("android.test.item_unavailable", R.string.android_test_item_unavailable, Managed.UNMANAGED), };
private String mSku;
private CatalogAdapter mCatalogAdapter;
@@ -99,8 +91,6 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
setupWidgets();
- BillingController.setDebug(true);
- BillingController.setConfiguration(this);
BillingController.registerObserver(this);
BillingController.checkBillingSupported(this);
updateOwnedItems();
@@ -140,7 +130,6 @@ public void onPurchaseRefunded(String itemId) {
@Override
protected void onDestroy() {
BillingController.unregisterObserver(this);
- BillingController.setConfiguration(null);
super.onDestroy();
}
@@ -182,12 +171,12 @@ public void onClick(View v) {
});
mSelectItemSpinner = (Spinner) findViewById(R.id.item_choices);
- mCatalogAdapter = new CatalogAdapter(this, CATALOG);
+ mCatalogAdapter = new CatalogAdapter(this, CatalogEntry.CATALOG);
mSelectItemSpinner.setAdapter(mCatalogAdapter);
mSelectItemSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- mSku = CATALOG[position].sku;
+ mSku = CatalogEntry.CATALOG[position].sku;
}
public void onNothingSelected(AdapterView<?> arg0) {
@@ -197,14 +186,4 @@ public void onNothingSelected(AdapterView<?> arg0) {
mOwnedItemsTable = (ListView) findViewById(R.id.owned_items);
}
-
- @Override
- public byte[] getObfuscationSalt() {
- return new byte[] {41, -90, -116, -41, 66, -53, 122, -110, -127, -96, -88, 77, 127, 115, 1, 73, 57, 110, 48, -116};
- }
-
- @Override
- public String getPublicKey() {
- return "your public key here";
- }
-}
+}
View
4 ...et/robotmedia/billing/example/CatalogAdapter.java → ...obotmedia/billing/example/aux/CatalogAdapter.java
@@ -1,9 +1,9 @@
-package net.robotmedia.billing.example;
+package net.robotmedia.billing.example.aux;
import java.util.ArrayList;
import java.util.List;
-import net.robotmedia.billing.example.CatalogEntry.Managed;
+import net.robotmedia.billing.example.aux.CatalogEntry.Managed;
import android.content.Context;
import android.view.View;
View
39 DungeonsRedux/src/net/robotmedia/billing/example/aux/CatalogEntry.java
@@ -0,0 +1,39 @@
+package net.robotmedia.billing.example.aux;
+
+import net.robotmedia.billing.example.R;
+
+public class CatalogEntry {
+
+ /**
+ * Each product in the catalog is either MANAGED or UNMANAGED. MANAGED means
+ * that the product can be purchased only once per user (such as a new level
+ * in a game). The purchase is remembered by Android Market and can be
+ * restored if this application is uninstalled and then re-installed.
+ * UNMANAGED is used for products that can be used up and purchased multiple
+ * times (such as poker chips). It is up to the application to keep track of
+ * UNMANAGED products for the user.
+ */
+ public enum Managed {
+ MANAGED, UNMANAGED
+ }
+
+ public String sku;
+ public int nameId;
+ public Managed managed;
+
+ public CatalogEntry(String sku, int nameId, Managed managed) {
+ this.sku = sku;
+ this.nameId = nameId;
+ this.managed = managed;
+ }
+
+ /** An array of product list entries for the products that can be purchased. */
+ public static final CatalogEntry[] CATALOG = new CatalogEntry[] {
+ new CatalogEntry("sword_001", R.string.two_handed_sword, Managed.MANAGED),
+ new CatalogEntry("potion_001", R.string.potions, Managed.UNMANAGED),
+ new CatalogEntry("android.test.purchased", R.string.android_test_purchased, Managed.UNMANAGED),
+ new CatalogEntry("android.test.canceled", R.string.android_test_canceled, Managed.UNMANAGED),
+ new CatalogEntry("android.test.refunded", R.string.android_test_refunded, Managed.UNMANAGED),
+ new CatalogEntry("android.test.item_unavailable", R.string.android_test_item_unavailable, Managed.UNMANAGED), };
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.