|
22 | 22 | import java.util.Collections;
|
23 | 23 | import java.util.Iterator;
|
24 | 24 |
|
25 |
| -// Billing |
26 |
| -import org.renpy.android.Configuration; |
27 |
| -import org.renpy.android.billing.BillingService.RequestPurchase; |
28 |
| -import org.renpy.android.billing.BillingService.RestoreTransactions; |
29 |
| -import org.renpy.android.billing.Consts.PurchaseState; |
30 |
| -import org.renpy.android.billing.Consts.ResponseCode; |
31 |
| -import org.renpy.android.billing.PurchaseObserver; |
32 |
| -import org.renpy.android.billing.BillingService; |
33 |
| -import org.renpy.android.billing.PurchaseDatabase; |
34 |
| -import org.renpy.android.billing.Consts; |
35 |
| -import org.renpy.android.billing.ResponseHandler; |
36 |
| -import org.renpy.android.billing.Security; |
37 | 25 | import android.os.Handler;
|
38 | 26 | import android.database.Cursor;
|
39 | 27 | import java.util.List;
|
@@ -133,10 +121,6 @@ protected void onCreate(Bundle savedInstanceState) {
|
133 | 121 | } catch (PackageManager.NameNotFoundException e) {
|
134 | 122 | }
|
135 | 123 |
|
136 |
| - if ( Configuration.use_billing ) { |
137 |
| - mBillingHandler = new Handler(); |
138 |
| - } |
139 |
| - |
140 | 124 | // Start showing an SDLSurfaceView.
|
141 | 125 | mView = new SDLSurfaceView(
|
142 | 126 | this,
|
@@ -333,8 +317,6 @@ public boolean onKeyUp(int keyCode, final KeyEvent event) {
|
333 | 317 | }
|
334 | 318 |
|
335 | 319 | protected void onDestroy() {
|
336 |
| - mPurchaseDatabase.close(); |
337 |
| - mBillingService.unbind(); |
338 | 320 |
|
339 | 321 | if (mView != null) {
|
340 | 322 | mView.onDestroy();
|
@@ -435,193 +417,4 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
|
435 | 417 | }
|
436 | 418 | }
|
437 | 419 |
|
438 |
| - //---------------------------------------------------------------------------- |
439 |
| - // Billing |
440 |
| - // |
441 |
| - class PythonPurchaseObserver extends PurchaseObserver { |
442 |
| - public PythonPurchaseObserver(Handler handler) { |
443 |
| - super(PythonActivity.this, handler); |
444 |
| - } |
445 |
| - |
446 |
| - @Override |
447 |
| - public void onBillingSupported(boolean supported, String type) { |
448 |
| - if (Consts.DEBUG) { |
449 |
| - Log.i(TAG, "supported: " + supported); |
450 |
| - } |
451 |
| - |
452 |
| - String sup = "1"; |
453 |
| - if ( !supported ) |
454 |
| - sup = "0"; |
455 |
| - if (type == null) |
456 |
| - type = Consts.ITEM_TYPE_INAPP; |
457 |
| - |
458 |
| - // add notification for python message queue |
459 |
| - mActivity.mBillingQueue.add("billingSupported|" + type + "|" + sup); |
460 |
| - |
461 |
| - // for managed items, restore the database |
462 |
| - if ( type == Consts.ITEM_TYPE_INAPP && supported ) { |
463 |
| - restoreDatabase(); |
464 |
| - } |
465 |
| - } |
466 |
| - |
467 |
| - @Override |
468 |
| - public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, |
469 |
| - int quantity, long purchaseTime, String developerPayload) { |
470 |
| - mActivity.mBillingQueue.add( |
471 |
| - "purchaseStateChange|" + itemId + "|" + purchaseState.toString()); |
472 |
| - } |
473 |
| - |
474 |
| - @Override |
475 |
| - public void onRequestPurchaseResponse(RequestPurchase request, |
476 |
| - ResponseCode responseCode) { |
477 |
| - mActivity.mBillingQueue.add( |
478 |
| - "requestPurchaseResponse|" + request.mProductId + "|" + responseCode.toString()); |
479 |
| - } |
480 |
| - |
481 |
| - @Override |
482 |
| - public void onRestoreTransactionsResponse(RestoreTransactions request, |
483 |
| - ResponseCode responseCode) { |
484 |
| - if (responseCode == ResponseCode.RESULT_OK) { |
485 |
| - mActivity.mBillingQueue.add("restoreTransaction|ok"); |
486 |
| - if (Consts.DEBUG) { |
487 |
| - Log.d(TAG, "completed RestoreTransactions request"); |
488 |
| - } |
489 |
| - // Update the shared preferences so that we don't perform |
490 |
| - // a RestoreTransactions again. |
491 |
| - SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); |
492 |
| - SharedPreferences.Editor edit = prefs.edit(); |
493 |
| - edit.putBoolean(DB_INITIALIZED, true); |
494 |
| - edit.commit(); |
495 |
| - } else { |
496 |
| - if (Consts.DEBUG) { |
497 |
| - Log.d(TAG, "RestoreTransactions error: " + responseCode); |
498 |
| - } |
499 |
| - |
500 |
| - mActivity.mBillingQueue.add( |
501 |
| - "restoreTransaction|error|" + responseCode.toString()); |
502 |
| - } |
503 |
| - } |
504 |
| - } |
505 |
| - |
506 |
| - /** |
507 |
| - * If the database has not been initialized, we send a |
508 |
| - * RESTORE_TRANSACTIONS request to Android Market to get the list of purchased items |
509 |
| - * for this user. This happens if the application has just been installed |
510 |
| - * or the user wiped data. We do not want to do this on every startup, rather, we want to do |
511 |
| - * only when the database needs to be initialized. |
512 |
| - */ |
513 |
| - private void restoreDatabase() { |
514 |
| - SharedPreferences prefs = getPreferences(MODE_PRIVATE); |
515 |
| - boolean initialized = prefs.getBoolean(DB_INITIALIZED, false); |
516 |
| - if (!initialized) { |
517 |
| - mBillingService.restoreTransactions(); |
518 |
| - } |
519 |
| - } |
520 |
| - |
521 |
| - /** An array of product list entries for the products that can be purchased. */ |
522 |
| - |
523 |
| - private enum Managed { MANAGED, UNMANAGED, SUBSCRIPTION } |
524 |
| - |
525 |
| - |
526 |
| - private PythonPurchaseObserver mPythonPurchaseObserver; |
527 |
| - private Handler mBillingHandler; |
528 |
| - private BillingService mBillingService; |
529 |
| - private PurchaseDatabase mPurchaseDatabase; |
530 |
| - private String mPayloadContents; |
531 |
| - public List<String> mBillingQueue; |
532 |
| - |
533 |
| - public void billingServiceStart_() { |
534 |
| - mBillingQueue = new ArrayList<String>(); |
535 |
| - |
536 |
| - // Start the billing part |
537 |
| - mPythonPurchaseObserver = new PythonPurchaseObserver(mBillingHandler); |
538 |
| - mBillingService = new BillingService(); |
539 |
| - mBillingService.setContext(this); |
540 |
| - mPurchaseDatabase = new PurchaseDatabase(this); |
541 |
| - |
542 |
| - ResponseHandler.register(mPythonPurchaseObserver); |
543 |
| - if (!mBillingService.checkBillingSupported()) { |
544 |
| - //showDialog(DIALOG_CANNOT_CONNECT_ID); |
545 |
| - Log.w(TAG, "NO BILLING SUPPORTED"); |
546 |
| - } |
547 |
| - if (!mBillingService.checkBillingSupported(Consts.ITEM_TYPE_SUBSCRIPTION)) { |
548 |
| - //showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID); |
549 |
| - Log.w(TAG, "NO SUBSCRIPTION SUPPORTED"); |
550 |
| - } |
551 |
| - } |
552 |
| - |
553 |
| - public void billingServiceStop_() { |
554 |
| - } |
555 |
| - |
556 |
| - public void billingBuy_(String mSku) { |
557 |
| - Managed mManagedType = Managed.MANAGED; |
558 |
| - if (Consts.DEBUG) { |
559 |
| - Log.d(TAG, "buying sku: " + mSku); |
560 |
| - } |
561 |
| - |
562 |
| - if (mManagedType == Managed.MANAGED) { |
563 |
| - if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) { |
564 |
| - Log.w(TAG, "ERROR IN BILLING REQUEST PURCHASE"); |
565 |
| - } |
566 |
| - } else if (mManagedType == Managed.SUBSCRIPTION) { |
567 |
| - if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) { |
568 |
| - Log.w(TAG, "ERROR IN BILLING REQUEST PURCHASE"); |
569 |
| - } |
570 |
| - } |
571 |
| - } |
572 |
| - |
573 |
| - public String billingGetPurchasedItems_() { |
574 |
| - String ownedItems = ""; |
575 |
| - Cursor cursor = mPurchaseDatabase.queryAllPurchasedItems(); |
576 |
| - if (cursor == null) |
577 |
| - return ""; |
578 |
| - |
579 |
| - try { |
580 |
| - int productIdCol = cursor.getColumnIndexOrThrow( |
581 |
| - PurchaseDatabase.PURCHASED_PRODUCT_ID_COL); |
582 |
| - int qtCol = cursor.getColumnIndexOrThrow( |
583 |
| - PurchaseDatabase.PURCHASED_QUANTITY_COL); |
584 |
| - while (cursor.moveToNext()) { |
585 |
| - String productId = cursor.getString(productIdCol); |
586 |
| - String qt = cursor.getString(qtCol); |
587 |
| - |
588 |
| - productId = Security.unobfuscate(this, Configuration.billing_salt, productId); |
589 |
| - if ( productId == null ) |
590 |
| - continue; |
591 |
| - |
592 |
| - if ( ownedItems != "" ) |
593 |
| - ownedItems += "\n"; |
594 |
| - ownedItems += productId + "," + qt; |
595 |
| - } |
596 |
| - } finally { |
597 |
| - cursor.close(); |
598 |
| - } |
599 |
| - |
600 |
| - return ownedItems; |
601 |
| - } |
602 |
| - |
603 |
| - |
604 |
| - static void billingServiceStart() { |
605 |
| - mActivity.billingServiceStart_(); |
606 |
| - } |
607 |
| - |
608 |
| - static void billingServiceStop() { |
609 |
| - mActivity.billingServiceStop_(); |
610 |
| - } |
611 |
| - |
612 |
| - static void billingBuy(String sku) { |
613 |
| - mActivity.billingBuy_(sku); |
614 |
| - } |
615 |
| - |
616 |
| - static String billingGetPurchasedItems() { |
617 |
| - return mActivity.billingGetPurchasedItems_(); |
618 |
| - } |
619 |
| - |
620 |
| - static String billingGetPendingMessage() { |
621 |
| - if (mActivity.mBillingQueue.isEmpty()) |
622 |
| - return null; |
623 |
| - return mActivity.mBillingQueue.remove(0); |
624 |
| - } |
625 |
| - |
626 | 420 | }
|
627 |
| - |
0 commit comments