[Android] Fix up in app purchase
This commit is contained in:
parent
084cdaef52
commit
eb0ef48364
|
@ -24,12 +24,15 @@ import emu.project64.inAppPurchase.IabHelper;
|
||||||
import emu.project64.inAppPurchase.IabHelper.IabAsyncInProgressException;
|
import emu.project64.inAppPurchase.IabHelper.IabAsyncInProgressException;
|
||||||
import emu.project64.inAppPurchase.IabResult;
|
import emu.project64.inAppPurchase.IabResult;
|
||||||
import emu.project64.inAppPurchase.Inventory;
|
import emu.project64.inAppPurchase.Inventory;
|
||||||
|
import emu.project64.inAppPurchase.Purchase;
|
||||||
import emu.project64.jni.NativeExports;
|
import emu.project64.jni.NativeExports;
|
||||||
import emu.project64.jni.SettingsID;
|
import emu.project64.jni.SettingsID;
|
||||||
import emu.project64.jni.SystemEvent;
|
import emu.project64.jni.SystemEvent;
|
||||||
import emu.project64.settings.GameSettingsActivity;
|
import emu.project64.settings.GameSettingsActivity;
|
||||||
import emu.project64.settings.SettingsActivity;
|
import emu.project64.settings.SettingsActivity;
|
||||||
|
import emu.project64.util.Utility;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -54,6 +57,7 @@ import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.webkit.WebView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -87,6 +91,10 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
IabBroadcastReceiver mBroadcastReceiver;
|
IabBroadcastReceiver mBroadcastReceiver;
|
||||||
|
|
||||||
public static final int GAME_DIR_REQUEST_CODE = 1;
|
public static final int GAME_DIR_REQUEST_CODE = 1;
|
||||||
|
static final String SKU_SAVESUPPORT = "save_support";
|
||||||
|
|
||||||
|
// (arbitrary) request code for the purchase flow
|
||||||
|
static final int RC_REQUEST = 10001;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent( Intent intent )
|
protected void onNewIntent( Intent intent )
|
||||||
|
@ -128,6 +136,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
// Oh noes, there was a problem.
|
// Oh noes, there was a problem.
|
||||||
Log.d("GalleryActivity", "Problem setting up in-app billing: " + result);
|
Log.d("GalleryActivity", "Problem setting up in-app billing: " + result);
|
||||||
// complain("Problem setting up in-app billing: " + result);
|
// complain("Problem setting up in-app billing: " + result);
|
||||||
|
mHasSaveSupport = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Have we been disposed of in the meantime? If so, quit.
|
// Have we been disposed of in the meantime? If so, quit.
|
||||||
|
@ -146,9 +155,12 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
|
|
||||||
// IAB is fully set up. Now, let's get an inventory of stuff we own.
|
// IAB is fully set up. Now, let's get an inventory of stuff we own.
|
||||||
Log.d("GalleryActivity", "Setup successful. Querying inventory.");
|
Log.d("GalleryActivity", "Setup successful. Querying inventory.");
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
mIabHelper.queryInventoryAsync(mGotInventoryListener);
|
mIabHelper.queryInventoryAsync(mGotInventoryListener);
|
||||||
} catch (IabAsyncInProgressException e) {
|
}
|
||||||
|
catch (IabAsyncInProgressException e)
|
||||||
|
{
|
||||||
//complain("Error querying inventory. Another async operation in progress.");
|
//complain("Error querying inventory. Another async operation in progress.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,16 +213,31 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enables or disables the "please wait" screen.
|
||||||
|
void setWaitScreen(boolean set)
|
||||||
|
{
|
||||||
|
if (set)
|
||||||
|
{
|
||||||
|
WebView webView = (WebView)findViewById(R.id.screen_wait);
|
||||||
|
webView.loadData(Utility.readAsset("loading.htm", ""), "text/html", "UTF8");
|
||||||
|
}
|
||||||
|
findViewById(R.id.screen_main).setVisibility(set ? View.GONE : View.VISIBLE);
|
||||||
|
findViewById(R.id.screen_wait).setVisibility(set ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
// Listener that's called when we finish querying the items and subscriptions we own
|
// Listener that's called when we finish querying the items and subscriptions we own
|
||||||
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
|
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener()
|
||||||
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
|
{
|
||||||
|
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
|
||||||
|
{
|
||||||
Log.d("GalleryActivity", "Query inventory finished.");
|
Log.d("GalleryActivity", "Query inventory finished.");
|
||||||
|
|
||||||
// Have we been disposed of in the meantime? If so, quit.
|
// Have we been disposed of in the meantime? If so, quit.
|
||||||
if (mIabHelper == null) return;
|
if (mIabHelper == null) return;
|
||||||
|
|
||||||
// Is it a failure?
|
// Is it a failure?
|
||||||
if (result.isFailure()) {
|
if (result.isFailure())
|
||||||
|
{
|
||||||
//complain("Failed to query inventory: " + result);
|
//complain("Failed to query inventory: " + result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -223,51 +250,55 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
* verifyDeveloperPayload().
|
* verifyDeveloperPayload().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Do we have the premium upgrade?
|
Purchase SaveSupportPurchase = inventory.getPurchase(SKU_SAVESUPPORT);
|
||||||
/*Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
|
Log.d("GalleryActivity", "Purchased save support " + (SaveSupportPurchase!= null ? "Yes" : "No"));
|
||||||
mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
|
if (SaveSupportPurchase != null)
|
||||||
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
|
{
|
||||||
|
mHasSaveSupport = true;
|
||||||
// First find out which subscription is auto renewing
|
|
||||||
Purchase gasMonthly = inventory.getPurchase(SKU_INFINITE_GAS_MONTHLY);
|
|
||||||
Purchase gasYearly = inventory.getPurchase(SKU_INFINITE_GAS_YEARLY);
|
|
||||||
if (gasMonthly != null && gasMonthly.isAutoRenewing()) {
|
|
||||||
mInfiniteGasSku = SKU_INFINITE_GAS_MONTHLY;
|
|
||||||
mAutoRenewEnabled = true;
|
|
||||||
} else if (gasYearly != null && gasYearly.isAutoRenewing()) {
|
|
||||||
mInfiniteGasSku = SKU_INFINITE_GAS_YEARLY;
|
|
||||||
mAutoRenewEnabled = true;
|
|
||||||
} else {
|
|
||||||
mInfiniteGasSku = "";
|
|
||||||
mAutoRenewEnabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The user is subscribed if either subscription exists, even if neither is auto
|
|
||||||
// renewing
|
|
||||||
mSubscribedToInfiniteGas = (gasMonthly != null && verifyDeveloperPayload(gasMonthly))
|
|
||||||
|| (gasYearly != null && verifyDeveloperPayload(gasYearly));
|
|
||||||
Log.d(TAG, "User " + (mSubscribedToInfiniteGas ? "HAS" : "DOES NOT HAVE")
|
|
||||||
+ " infinite gas subscription.");
|
|
||||||
if (mSubscribedToInfiniteGas) mTank = TANK_MAX;
|
|
||||||
|
|
||||||
// Check for gas delivery -- if we own gas, we should fill up the tank immediately
|
|
||||||
Purchase gasPurchase = inventory.getPurchase(SKU_GAS);
|
|
||||||
if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) {
|
|
||||||
Log.d(TAG, "We have gas. Consuming it.");
|
|
||||||
try {
|
|
||||||
mHelper.consumeAsync(inventory.getPurchase(SKU_GAS), mConsumeFinishedListener);
|
|
||||||
} catch (IabAsyncInProgressException e) {
|
|
||||||
complain("Error consuming gas. Another async operation in progress.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateUi();
|
|
||||||
setWaitScreen(false);
|
setWaitScreen(false);
|
||||||
Log.d(TAG, "Initial inventory query finished; enabling main UI.");*/
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener()
|
||||||
|
{
|
||||||
|
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
|
||||||
|
{
|
||||||
|
Log.d("GalleryActivity", "Purchase finished: " + result + ", purchase: " + purchase);
|
||||||
|
// if we were disposed of in the meantime, quit.
|
||||||
|
if (mIabHelper == null) return;
|
||||||
|
|
||||||
|
if (result.isFailure())
|
||||||
|
{
|
||||||
|
Log.e("GalleryActivity", "**** Purcahse Error: " + result);
|
||||||
|
alert("Save Support Upgrade failed\n\n" + result.getMessage());
|
||||||
|
setWaitScreen(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d("GalleryActivity", "Purchase successful.");
|
||||||
|
|
||||||
|
if (purchase.getSku().equals(SKU_SAVESUPPORT))
|
||||||
|
{
|
||||||
|
// bought the premium upgrade!
|
||||||
|
Log.d("GalleryActivity", "Purchase is save support. Congratulating user.");
|
||||||
|
alert("Thank you for upgrading to have save support!");
|
||||||
|
mHasSaveSupport = true;
|
||||||
|
setWaitScreen(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void alert(String message)
|
||||||
|
{
|
||||||
|
AlertDialog.Builder bld = new AlertDialog.Builder(this);
|
||||||
|
bld.setMessage(message);
|
||||||
|
bld.setNeutralButton("OK", null);
|
||||||
|
Log.d("GalleryActivity", "Showing alert dialog: " + message);
|
||||||
|
bld.create().show();
|
||||||
|
}
|
||||||
|
|
||||||
public void receivedBroadcast()
|
public void receivedBroadcast()
|
||||||
{
|
{
|
||||||
// Received a broadcast notification that the inventory of items has changed
|
// Received a broadcast notification that the inventory of items has changed
|
||||||
|
@ -318,8 +349,12 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
startActivity( SettingsIntent );
|
startActivity( SettingsIntent );
|
||||||
return true;
|
return true;
|
||||||
case R.id.menuItem_forum:
|
case R.id.menuItem_forum:
|
||||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://forum.pj64-emu.com/forumdisplay.php?f=13"));
|
Intent ForumIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://forum.pj64-emu.com/forumdisplay.php?f=13"));
|
||||||
startActivity(browserIntent);
|
startActivity(ForumIntent);
|
||||||
|
return true;
|
||||||
|
case R.id.menuItem_reportBug:
|
||||||
|
Intent IssueIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/project64/project64/issues"));
|
||||||
|
startActivity(IssueIntent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menuItem_about:
|
case R.id.menuItem_about:
|
||||||
Intent AboutIntent = new Intent(this, AboutActivity.class);
|
Intent AboutIntent = new Intent(this, AboutActivity.class);
|
||||||
|
@ -460,6 +495,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
};
|
};
|
||||||
|
|
||||||
final Context finalContext = this;
|
final Context finalContext = this;
|
||||||
|
final Activity finalActivity = this;
|
||||||
AlertDialog.Builder GameMenu = new AlertDialog.Builder(finalContext);
|
AlertDialog.Builder GameMenu = new AlertDialog.Builder(finalContext);
|
||||||
GameMenu.setTitle(NativeExports.SettingsLoadString(SettingsID.Game_GoodName.getValue()));
|
GameMenu.setTitle(NativeExports.SettingsLoadString(SettingsID.Game_GoodName.getValue()));
|
||||||
GameMenu.setAdapter(adapter, new DialogInterface.OnClickListener()
|
GameMenu.setAdapter(adapter, new DialogInterface.OnClickListener()
|
||||||
|
@ -469,14 +505,29 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
{
|
{
|
||||||
if ((item == 0 || item == 1) && !mHasSaveSupport)
|
if ((item == 0 || item == 1) && !mHasSaveSupport)
|
||||||
{
|
{
|
||||||
//Purchase save support
|
AlertDialog.Builder ResetPrompt = new AlertDialog.Builder(finalContext);
|
||||||
/*try {
|
ResetPrompt
|
||||||
mHelper.launchPurchaseFlow(this, SKU_PREMIUM, RC_REQUEST,
|
.setTitle(getText(R.string.GetSaveSupport_title))
|
||||||
mPurchaseFinishedListener, payload);
|
.setMessage(getText(R.string.GetSaveSupport_message))
|
||||||
} catch (IabAsyncInProgressException e) {
|
.setPositiveButton(R.string.GetSaveSupport_OkButton, new DialogInterface.OnClickListener()
|
||||||
complain("Error launching purchase flow. Another async operation in progress.");
|
{
|
||||||
setWaitScreen(false);
|
public void onClick(DialogInterface dialog, int id)
|
||||||
}*/
|
{
|
||||||
|
setWaitScreen(true);
|
||||||
|
//Purchase save support
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String payload = NativeExports.appVersion();
|
||||||
|
mIabHelper.launchPurchaseFlow(finalActivity, SKU_SAVESUPPORT, RC_REQUEST, mPurchaseFinishedListener, payload);
|
||||||
|
}
|
||||||
|
catch (IabAsyncInProgressException e)
|
||||||
|
{
|
||||||
|
setWaitScreen(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, this)
|
||||||
|
.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (item == 0)
|
if (item == 0)
|
||||||
|
@ -499,16 +550,17 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
{
|
{
|
||||||
public void onClick(DialogInterface dialog, int id)
|
public void onClick(DialogInterface dialog, int id)
|
||||||
{
|
{
|
||||||
//delete folder
|
String[]entries = SaveDir.list();
|
||||||
//launchGameActivity();
|
for(String s: entries)
|
||||||
}
|
{
|
||||||
})
|
File currentFile = new File(SaveDir.getPath(),s);
|
||||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener()
|
currentFile.delete();
|
||||||
{
|
}
|
||||||
public void onClick(DialogInterface dialog, int id)
|
SaveDir.delete();
|
||||||
{
|
launchGameActivity();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, this)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
else if (item == 3)
|
else if (item == 3)
|
||||||
|
@ -554,6 +606,8 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||||
{
|
{
|
||||||
|
Log.d("GalleryActivity", "onActivityResult(" + requestCode + "," + resultCode + "," + data);
|
||||||
|
|
||||||
// Check which request we're responding to
|
// Check which request we're responding to
|
||||||
if (requestCode == GAME_DIR_REQUEST_CODE)
|
if (requestCode == GAME_DIR_REQUEST_CODE)
|
||||||
{
|
{
|
||||||
|
@ -570,6 +624,15 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Pass on the activity result to the helper for handling
|
||||||
|
if (mIabHelper != null && !mIabHelper.handleActivityResult(requestCode, resultCode, data))
|
||||||
|
{
|
||||||
|
// not handled, so handle it ourselves (here's where you'd
|
||||||
|
// perform any handling of activity results not related to in-app
|
||||||
|
// billing...
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshGrid( )
|
void refreshGrid( )
|
||||||
|
|
|
@ -81,10 +81,10 @@ public class GameOverlay extends View implements TouchController.OnStateChangedL
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw( Canvas canvas )
|
protected void onDraw( Canvas canvas )
|
||||||
{
|
{
|
||||||
if( mTouchMap == null || canvas == null )
|
if(canvas == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( mDrawingEnabled )
|
if( mTouchMap != null && mDrawingEnabled )
|
||||||
{
|
{
|
||||||
// Redraw the static buttons
|
// Redraw the static buttons
|
||||||
mTouchMap.drawButtons( canvas );
|
mTouchMap.drawButtons( canvas );
|
||||||
|
|
Loading…
Reference in New Issue