Skip to content

Commit

Permalink
Moved configuration to Application subclass and refactored auxiliary …
Browse files Browse the repository at this point in the history
…classes to their own package.
  • Loading branch information
Robot Media committed Jul 23, 2011
1 parent da7206a commit d4e3cb2
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 64 deletions.
2 changes: 1 addition & 1 deletion DungeonsRedux/AndroidManifest.xml
Expand Up @@ -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" />
Expand Down
12 changes: 6 additions & 6 deletions 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
Expand All @@ -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.

-------------------------------------
Expand Down
25 changes: 25 additions & 0 deletions 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";
}
});
}

}
28 changes: 0 additions & 28 deletions DungeonsRedux/src/net/robotmedia/billing/example/CatalogEntry.java

This file was deleted.

33 changes: 6 additions & 27 deletions DungeonsRedux/src/net/robotmedia/billing/example/Dungeons.java
Expand Up @@ -24,17 +24,17 @@

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;

/**
* 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";

Expand All @@ -50,14 +50,6 @@ public class Dungeons extends Activity implements IBillingObserver, IConfigurati

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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -140,7 +130,6 @@ public void onPurchaseRefunded(String itemId) {
@Override
protected void onDestroy() {
BillingController.unregisterObserver(this);
BillingController.setConfiguration(null);
super.onDestroy();
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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";
}
}
}
@@ -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;
Expand Down
@@ -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), };

}

0 comments on commit d4e3cb2

Please sign in to comment.