// Path: src/com/suchagit/android2cloud/BillingService.java
// class RequestPurchase extends BillingRequest {
//     public final String mProductId;
//     public final String mDeveloperPayload;
// 
//     public RequestPurchase(String itemId) {
//         this(itemId, null);
//     }
// 
//     public RequestPurchase(String itemId, String developerPayload) {
//         // This object is never created as a side effect of starting this
//         // service so we pass -1 as the startId to indicate that we should
//         // not stop this service after executing this request.
//         super(-1);
//         mProductId = itemId;
//         mDeveloperPayload = developerPayload;
//     }
// 
//     @Override
//     protected long run() throws RemoteException {
//         Bundle request = makeRequestBundle("REQUEST_PURCHASE");
//         request.putString(Consts.BILLING_REQUEST_ITEM_ID, mProductId);
//         // Note that the developer payload is optional.
//         if (mDeveloperPayload != null) {
//             request.putString(Consts.BILLING_REQUEST_DEVELOPER_PAYLOAD, mDeveloperPayload);
//         }
//         Bundle response = mService.sendBillingRequest(request);
//         PendingIntent pendingIntent
//                 = response.getParcelable(Consts.BILLING_RESPONSE_PURCHASE_INTENT);
//         if (pendingIntent == null) {
//             Log.e(TAG, "Error with requestPurchase");
//             return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID;
//         }
// 
//         Intent intent = new Intent();
//         ResponseHandler.buyPageIntentResponse(pendingIntent, intent);
//         return response.getLong(Consts.BILLING_RESPONSE_REQUEST_ID,
//                 Consts.BILLING_RESPONSE_INVALID_REQUEST_ID);
//     }
// 
//     @Override
//     protected void responseCodeReceived(ResponseCode responseCode) {
//         ResponseHandler.responseCodeReceived(BillingService.this, this, responseCode);
//     }
// }
// 
// Path: src/com/suchagit/android2cloud/Consts.java
// public enum PurchaseState {
//     // Responses to requestPurchase or restoreTransactions.
//     PURCHASED,   // User was charged for the order.
//     CANCELED,    // The charge failed on the server.
//     REFUNDED;    // User received a refund for the order.
// 
//     // Converts from an ordinal value to the PurchaseState
//     public static PurchaseState valueOf(int index) {
//         PurchaseState[] values = PurchaseState.values();
//         if (index < 0 || index >= values.length) {
//             return CANCELED;
//         }
//         return values[index];
//     }
// }
// 
// Path: src/com/suchagit/android2cloud/Consts.java
// public enum ResponseCode {
//     RESULT_OK,
//     RESULT_USER_CANCELED,
//     RESULT_SERVICE_UNAVAILABLE,
//     RESULT_BILLING_UNAVAILABLE,
//     RESULT_ITEM_UNAVAILABLE,
//     RESULT_DEVELOPER_ERROR,
//     RESULT_ERROR;
// 
//     // Converts from an ordinal value to the ResponseCode
//     public static ResponseCode valueOf(int index) {
//         ResponseCode[] values = ResponseCode.values();
//         if (index < 0 || index >= values.length) {
//             return RESULT_ERROR;
//         }
//         return values[index];
//     }
// }


import com.suchagit.android2cloud.BillingService.RequestPurchase;
import com.suchagit.android2cloud.Consts.PurchaseState;
import com.suchagit.android2cloud.Consts.ResponseCode;
import android.app.Activity;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Handler;
import android.util.Log;
import java.lang.reflect.Method;
// Copyright 2010 Google Inc. All Rights Reserved.

package com.suchagit.android2cloud;




/**
 * An interface for observing changes related to purchases. The main application
 * extends this class and registers an instance of that derived class with
 * {@link ResponseHandler}. The main application implements the callbacks
 * {@link #onBillingSupported(boolean)} and
 * {@link #onPurchaseStateChange(PurchaseState, String, int, long)}.  These methods
 * are used to update the UI.
 */
public abstract class PurchaseObserver {
    private static final String TAG = "PurchaseObserver";
    private final Activity mActivity;
    private final Handler mHandler;
    private Method mStartIntentSender;
    private Object[] mStartIntentSenderArgs = new Object[5];
    @SuppressWarnings({ "rawtypes" })
	private static final Class[] START_INTENT_SENDER_SIG = new Class[] {
        IntentSender.class, Intent.class, int.class, int.class, int.class
    };

    public PurchaseObserver(Activity activity, Handler handler) {
        mActivity = activity;
        mHandler = handler;
        initCompatibilityLayer();
    }

    /**
     * This is the callback that is invoked when Android Market responds to the
     * {@link BillingService#checkBillingSupported()} request.
     * @param supported true if in-app billing is supported.
     */
    public abstract void onBillingSupported(boolean supported);

    /**
     * This is the callback that is invoked when an item is purchased,
     * refunded, or canceled.  It is the callback invoked in response to
     * calling {@link BillingService#requestPurchase(String)}.  It may also
     * be invoked asynchronously when a purchase is made on another device
     * (if the purchase was for a Market-managed item), or if the purchase
     * was refunded, or the charge was canceled.  This handles the UI
     * update.  The database update is handled in
     * {@link ResponseHandler#purchaseResponse(Context, PurchaseState,
     * String, String, long)}.
     * @param purchaseState the purchase state of the item
     * @param itemId a string identifying the item (the "SKU")
     * @param quantity the current quantity of this item after the purchase
     * @param purchaseTime the time the product was purchased, in
     * milliseconds since the epoch (Jan 1, 1970)
     * @param orderId the Google Checkout order ID number
     */
// Path: src/com/suchagit/android2cloud/BillingService.java
// class RequestPurchase extends BillingRequest {
//     public final String mProductId;
//     public final String mDeveloperPayload;
// 
//     public RequestPurchase(String itemId) {
//         this(itemId, null);
//     }
// 
//     public RequestPurchase(String itemId, String developerPayload) {
//         // This object is never created as a side effect of starting this
//         // service so we pass -1 as the startId to indicate that we should
//         // not stop this service after executing this request.
//         super(-1);
//         mProductId = itemId;
//         mDeveloperPayload = developerPayload;
//     }
// 
//     @Override
//     protected long run() throws RemoteException {
//         Bundle request = makeRequestBundle("REQUEST_PURCHASE");
//         request.putString(Consts.BILLING_REQUEST_ITEM_ID, mProductId);
//         // Note that the developer payload is optional.
//         if (mDeveloperPayload != null) {
//             request.putString(Consts.BILLING_REQUEST_DEVELOPER_PAYLOAD, mDeveloperPayload);
//         }
//         Bundle response = mService.sendBillingRequest(request);
//         PendingIntent pendingIntent
//                 = response.getParcelable(Consts.BILLING_RESPONSE_PURCHASE_INTENT);
//         if (pendingIntent == null) {
//             Log.e(TAG, "Error with requestPurchase");
//             return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID;
//         }
// 
//         Intent intent = new Intent();
//         ResponseHandler.buyPageIntentResponse(pendingIntent, intent);
//         return response.getLong(Consts.BILLING_RESPONSE_REQUEST_ID,
//                 Consts.BILLING_RESPONSE_INVALID_REQUEST_ID);
//     }
// 
//     @Override
//     protected void responseCodeReceived(ResponseCode responseCode) {
//         ResponseHandler.responseCodeReceived(BillingService.this, this, responseCode);
//     }
// }
// 
// Path: src/com/suchagit/android2cloud/Consts.java
// public enum PurchaseState {
//     // Responses to requestPurchase or restoreTransactions.
//     PURCHASED,   // User was charged for the order.
//     CANCELED,    // The charge failed on the server.
//     REFUNDED;    // User received a refund for the order.
// 
//     // Converts from an ordinal value to the PurchaseState
//     public static PurchaseState valueOf(int index) {
//         PurchaseState[] values = PurchaseState.values();
//         if (index < 0 || index >= values.length) {
//             return CANCELED;
//         }
//         return values[index];
//     }
// }
// 
// Path: src/com/suchagit/android2cloud/Consts.java
// public enum ResponseCode {
//     RESULT_OK,
//     RESULT_USER_CANCELED,
//     RESULT_SERVICE_UNAVAILABLE,
//     RESULT_BILLING_UNAVAILABLE,
//     RESULT_ITEM_UNAVAILABLE,
//     RESULT_DEVELOPER_ERROR,
//     RESULT_ERROR;
// 
//     // Converts from an ordinal value to the ResponseCode
//     public static ResponseCode valueOf(int index) {
//         ResponseCode[] values = ResponseCode.values();
//         if (index < 0 || index >= values.length) {
//             return RESULT_ERROR;
//         }
//         return values[index];
//     }
// }


// Path: src/com/suchagit/android2cloud/PurchaseObserver.java
import com.suchagit.android2cloud.BillingService.RequestPurchase;
import com.suchagit.android2cloud.Consts.PurchaseState;
import com.suchagit.android2cloud.Consts.ResponseCode;
import android.app.Activity;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Handler;
import android.util.Log;
import java.lang.reflect.Method;

// Copyright 2010 Google Inc. All Rights Reserved.

package com.suchagit.android2cloud;




/**
 * An interface for observing changes related to purchases. The main application
 * extends this class and registers an instance of that derived class with
 * {@link ResponseHandler}. The main application implements the callbacks
 * {@link #onBillingSupported(boolean)} and
 * {@link #onPurchaseStateChange(PurchaseState, String, int, long)}.  These methods
 * are used to update the UI.
 */
public abstract class PurchaseObserver {
    private static final String TAG = "PurchaseObserver";
    private final Activity mActivity;
    private final Handler mHandler;
    private Method mStartIntentSender;
    private Object[] mStartIntentSenderArgs = new Object[5];
    @SuppressWarnings({ "rawtypes" })
	private static final Class[] START_INTENT_SENDER_SIG = new Class[] {
        IntentSender.class, Intent.class, int.class, int.class, int.class
    };

    public PurchaseObserver(Activity activity, Handler handler) {
        mActivity = activity;
        mHandler = handler;
        initCompatibilityLayer();
    }

    /**
     * This is the callback that is invoked when Android Market responds to the
     * {@link BillingService#checkBillingSupported()} request.
     * @param supported true if in-app billing is supported.
     */
    public abstract void onBillingSupported(boolean supported);

    /**
     * This is the callback that is invoked when an item is purchased,
     * refunded, or canceled.  It is the callback invoked in response to
     * calling {@link BillingService#requestPurchase(String)}.  It may also
     * be invoked asynchronously when a purchase is made on another device
     * (if the purchase was for a Market-managed item), or if the purchase
     * was refunded, or the charge was canceled.  This handles the UI
     * update.  The database update is handled in
     * {@link ResponseHandler#purchaseResponse(Context, PurchaseState,
     * String, String, long)}.
     * @param purchaseState the purchase state of the item
     * @param itemId a string identifying the item (the "SKU")
     * @param quantity the current quantity of this item after the purchase
     * @param purchaseTime the time the product was purchased, in
     * milliseconds since the epoch (Jan 1, 1970)
     * @param orderId the Google Checkout order ID number
     */
    public abstract void onPurchaseStateChange(PurchaseState purchaseState,