Skip to content

Commit d4e3cb2

Browse files
author
Robot Media
committed
Moved configuration to Application subclass and refactored auxiliary classes to their own package.
1 parent da7206a commit d4e3cb2

File tree

7 files changed

+79
-64
lines changed

7 files changed

+79
-64
lines changed

DungeonsRedux/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<!-- Add this permission to your manifest -->
77
<uses-permission android:name="com.android.vending.BILLING" />
88

9-
<application android:icon="@drawable/icon" android:label="@string/app_name">
9+
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name=".Application">
1010
<activity android:name=".Dungeons" android:label="@string/app_name">
1111
<intent-filter>
1212
<action android:name="android.intent.action.MAIN" />

DungeonsRedux/README

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
This package contains a sample app -Dungeons Redux- that shows how to use the Android Billing
2-
Library (https://github.com/robotmedia/AndroidBillingLibrary). It does not intend to be an
3-
example of how to use in-app billing in general.
1+
Dungeons Redux is a sample app that shows how to use the Android Billing Library by Robot Media.
2+
It is a simplified version of the Dungeons in-app billing sample app provided by Google.
43

5-
Dungeons Redux is a simplified version of the Dungeons sample app provided by Google.
4+
Dungeons Redux does not intend to be an example of how to use in-app billing in general, just
5+
Android Billing Library.
66

77
-------------------------------------
88
Configuring the sample application
@@ -17,13 +17,13 @@ code, do the following:
1717
2. On the upper left part of the page, under your name, click Edit Profile.
1818
3. On the Edit Profile page, scroll down to the Licensing & In-app Billing panel.
1919
4. Copy your public key to the clipboard.
20-
5. Open src/net/robotmedia/billing/example/Dungeons.java in the editor of your choice.
20+
5. Open src/net/robotmedia/billing/example/Application.java in the editor of your choice.
2121
6. Search for the following line:
2222
return "your public key here";
2323
7. Replace the string with your public key.
2424
8. Save the file.
2525

26-
After you add your public key to the Dungeons.java file, you can compile the application as you
26+
After you add your public key to the Application.java file, you can compile the application as you
2727
normally would.
2828

2929
-------------------------------------
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.robotmedia.billing.example;
2+
3+
import net.robotmedia.billing.BillingController;
4+
5+
public class Application extends android.app.Application {
6+
7+
@Override
8+
public void onCreate() {
9+
super.onCreate();
10+
BillingController.setDebug(true);
11+
BillingController.setConfiguration(new BillingController.IConfiguration() {
12+
13+
@Override
14+
public byte[] getObfuscationSalt() {
15+
return new byte[] {41, -90, -116, -41, 66, -53, 122, -110, -127, -96, -88, 77, 127, 115, 1, 73, 57, 110, 48, -116};
16+
}
17+
18+
@Override
19+
public String getPublicKey() {
20+
return "your public key here";
21+
}
22+
});
23+
}
24+
25+
}

DungeonsRedux/src/net/robotmedia/billing/example/CatalogEntry.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

DungeonsRedux/src/net/robotmedia/billing/example/Dungeons.java

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424

2525
import net.robotmedia.billing.BillingController;
2626
import net.robotmedia.billing.IBillingObserver;
27-
import net.robotmedia.billing.BillingController.IConfiguration;
2827
import net.robotmedia.billing.example.R;
29-
import net.robotmedia.billing.example.CatalogEntry.Managed;
28+
import net.robotmedia.billing.example.aux.CatalogAdapter;
29+
import net.robotmedia.billing.example.aux.CatalogEntry;
3030
import net.robotmedia.billing.model.Transaction;
3131
import net.robotmedia.billing.model.Transaction.PurchaseState;
3232

3333
/**
3434
* A sample application based on the original Dungeons to demonstrate how to use
3535
* BillingController and implement IBillingObserver.
3636
*/
37-
public class Dungeons extends Activity implements IBillingObserver, IConfiguration {
37+
public class Dungeons extends Activity implements IBillingObserver {
3838

3939
private static final String TAG = "Dungeons";
4040

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

5151
private static final int DIALOG_BILLING_NOT_SUPPORTED_ID = 2;
5252

53-
/** An array of product list entries for the products that can be purchased. */
54-
private static final CatalogEntry[] CATALOG = new CatalogEntry[] {
55-
new CatalogEntry("sword_001", R.string.two_handed_sword, Managed.MANAGED),
56-
new CatalogEntry("potion_001", R.string.potions, Managed.UNMANAGED),
57-
new CatalogEntry("android.test.purchased", R.string.android_test_purchased, Managed.UNMANAGED),
58-
new CatalogEntry("android.test.canceled", R.string.android_test_canceled, Managed.UNMANAGED),
59-
new CatalogEntry("android.test.refunded", R.string.android_test_refunded, Managed.UNMANAGED),
60-
new CatalogEntry("android.test.item_unavailable", R.string.android_test_item_unavailable, Managed.UNMANAGED), };
6153
private String mSku;
6254

6355
private CatalogAdapter mCatalogAdapter;
@@ -99,8 +91,6 @@ public void onCreate(Bundle savedInstanceState) {
9991
setContentView(R.layout.main);
10092

10193
setupWidgets();
102-
BillingController.setDebug(true);
103-
BillingController.setConfiguration(this);
10494
BillingController.registerObserver(this);
10595
BillingController.checkBillingSupported(this);
10696
updateOwnedItems();
@@ -140,7 +130,6 @@ public void onPurchaseRefunded(String itemId) {
140130
@Override
141131
protected void onDestroy() {
142132
BillingController.unregisterObserver(this);
143-
BillingController.setConfiguration(null);
144133
super.onDestroy();
145134
}
146135

@@ -182,12 +171,12 @@ public void onClick(View v) {
182171
});
183172

184173
mSelectItemSpinner = (Spinner) findViewById(R.id.item_choices);
185-
mCatalogAdapter = new CatalogAdapter(this, CATALOG);
174+
mCatalogAdapter = new CatalogAdapter(this, CatalogEntry.CATALOG);
186175
mSelectItemSpinner.setAdapter(mCatalogAdapter);
187176
mSelectItemSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
188177

189178
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
190-
mSku = CATALOG[position].sku;
179+
mSku = CatalogEntry.CATALOG[position].sku;
191180
}
192181

193182
public void onNothingSelected(AdapterView<?> arg0) {
@@ -197,14 +186,4 @@ public void onNothingSelected(AdapterView<?> arg0) {
197186

198187
mOwnedItemsTable = (ListView) findViewById(R.id.owned_items);
199188
}
200-
201-
@Override
202-
public byte[] getObfuscationSalt() {
203-
return new byte[] {41, -90, -116, -41, 66, -53, 122, -110, -127, -96, -88, 77, 127, 115, 1, 73, 57, 110, 48, -116};
204-
}
205-
206-
@Override
207-
public String getPublicKey() {
208-
return "your public key here";
209-
}
210-
}
189+
}

DungeonsRedux/src/net/robotmedia/billing/example/CatalogAdapter.java renamed to DungeonsRedux/src/net/robotmedia/billing/example/aux/CatalogAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package net.robotmedia.billing.example;
1+
package net.robotmedia.billing.example.aux;
22

33
import java.util.ArrayList;
44
import java.util.List;
55

6-
import net.robotmedia.billing.example.CatalogEntry.Managed;
6+
import net.robotmedia.billing.example.aux.CatalogEntry.Managed;
77

88
import android.content.Context;
99
import android.view.View;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.robotmedia.billing.example.aux;
2+
3+
import net.robotmedia.billing.example.R;
4+
5+
public class CatalogEntry {
6+
7+
/**
8+
* Each product in the catalog is either MANAGED or UNMANAGED. MANAGED means
9+
* that the product can be purchased only once per user (such as a new level
10+
* in a game). The purchase is remembered by Android Market and can be
11+
* restored if this application is uninstalled and then re-installed.
12+
* UNMANAGED is used for products that can be used up and purchased multiple
13+
* times (such as poker chips). It is up to the application to keep track of
14+
* UNMANAGED products for the user.
15+
*/
16+
public enum Managed {
17+
MANAGED, UNMANAGED
18+
}
19+
20+
public String sku;
21+
public int nameId;
22+
public Managed managed;
23+
24+
public CatalogEntry(String sku, int nameId, Managed managed) {
25+
this.sku = sku;
26+
this.nameId = nameId;
27+
this.managed = managed;
28+
}
29+
30+
/** An array of product list entries for the products that can be purchased. */
31+
public static final CatalogEntry[] CATALOG = new CatalogEntry[] {
32+
new CatalogEntry("sword_001", R.string.two_handed_sword, Managed.MANAGED),
33+
new CatalogEntry("potion_001", R.string.potions, Managed.UNMANAGED),
34+
new CatalogEntry("android.test.purchased", R.string.android_test_purchased, Managed.UNMANAGED),
35+
new CatalogEntry("android.test.canceled", R.string.android_test_canceled, Managed.UNMANAGED),
36+
new CatalogEntry("android.test.refunded", R.string.android_test_refunded, Managed.UNMANAGED),
37+
new CatalogEntry("android.test.item_unavailable", R.string.android_test_item_unavailable, Managed.UNMANAGED), };
38+
39+
}

0 commit comments

Comments
 (0)