[Android] Update the support window code

This commit is contained in:
zilmar 2016-12-24 07:54:48 +11:00
parent 267d19a93b
commit 9410db5981
1 changed files with 57 additions and 169 deletions

View File

@ -98,7 +98,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
// The IAB helper object // The IAB helper object
IabHelper mIabHelper; IabHelper mIabHelper;
private boolean mHasSaveSupport = true; private boolean mHasSaveSupport = false;
private boolean mPj64Supporter = false; private boolean mPj64Supporter = false;
// Provides purchase notification while this app is running // Provides purchase notification while this app is running
@ -115,8 +115,6 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
static final int RC_REQUEST = 10001; static final int RC_REQUEST = 10001;
static final int RC_SETTINGS = 10002; static final int RC_SETTINGS = 10002;
static boolean mShownSupportWindow = true;
@Override @Override
protected void onNewIntent( Intent intent ) protected void onNewIntent( Intent intent )
{ {
@ -347,11 +345,6 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
setWaitScreen(false); setWaitScreen(false);
if (!mPj64Supporter && ShouldShowSupportWindow())
{
ShowSupportWindow();
}
} }
}; };
@ -507,8 +500,11 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
return false; return false;
} }
private void StartGameMenu (File GameSaveDir, boolean ShowSettings) private void StartGameMenu (boolean ShowSettings)
{ {
File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue()));
final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue()));
class Item class Item
{ {
public final String text; public final String text;
@ -526,16 +522,16 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
List<Item>menuItemLst = new ArrayList<Item>(); List<Item>menuItemLst = new ArrayList<Item>();
if (mHasSaveSupport) if (ShouldShowSupportWindow())
{
menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_controller));
menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_play));
}
else
{ {
menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_lock)); menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_lock));
menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_lock)); menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_lock));
} }
else
{
menuItemLst.add(new Item("Resume from Native save", R.drawable.ic_controller));
menuItemLst.add(new Item("Resume from Auto save", R.drawable.ic_play));
}
menuItemLst.add(new Item("Restart", R.drawable.ic_refresh)); menuItemLst.add(new Item("Restart", R.drawable.ic_refresh));
if (ShowSettings && !NativeExports.SettingsLoadBool(SettingsID.UserInterface_BasicMode.getValue())) if (ShowSettings && !NativeExports.SettingsLoadBool(SettingsID.UserInterface_BasicMode.getValue()))
{ {
@ -611,31 +607,9 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
@Override @Override
public void onClick(DialogInterface dialog, int item) public void onClick(DialogInterface dialog, int item)
{ {
if ((item == 0 || item == 1) && !mHasSaveSupport) if ((item == 0 || item == 1) && ShouldShowSupportWindow())
{ {
AlertDialog.Builder ResetPrompt = new AlertDialog.Builder(finalContext); ShowSupportWindow();
ResetPrompt
.setTitle(getText(R.string.GetSaveSupport_title))
.setMessage(getText(R.string.GetSaveSupport_message))
.setPositiveButton(R.string.GetSaveSupport_OkButton, new DialogInterface.OnClickListener()
{
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)
@ -665,6 +639,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
currentFile.delete(); currentFile.delete();
} }
SaveDir.delete(); SaveDir.delete();
NativeExports.UISettingsSaveDword(UISettingID.Game_RunCount.getValue(), 0);
launchGameActivity(); launchGameActivity();
} }
}) })
@ -684,14 +659,14 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
public void onGalleryItemClick( GalleryItem item ) public void onGalleryItemClick( GalleryItem item )
{ {
NativeExports.LoadGame(item.romFile.getAbsolutePath()); NativeExports.LoadGame(item.romFile.getAbsolutePath());
File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue())); if (ShouldShowSupportWindow())
final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue()));
if (GameSaveDir.exists() && !mHasSaveSupport)
{ {
StartGameMenu(GameSaveDir, false); ShowSupportWindow();
} }
else else
{ {
File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue()));
final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue()));
if (HasAutoSave(GameSaveDir)) if (HasAutoSave(GameSaveDir))
{ {
NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0); NativeExports.SettingsSaveDword(SettingsID.Game_CurrentSaveState.getValue(), 0);
@ -704,10 +679,15 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
public boolean onGalleryItemLongClick( GalleryItem item ) public boolean onGalleryItemLongClick( GalleryItem item )
{ {
NativeExports.LoadGame(item.romFile.getAbsolutePath()); NativeExports.LoadGame(item.romFile.getAbsolutePath());
File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue())); if (ShouldShowSupportWindow())
final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue())); {
ShowSupportWindow();
StartGameMenu(GameSaveDir, true); }
else
{
StartGameMenu(true);
}
Log.d("GalleryActivity", "onGalleryItemLongClick 4");
return true; return true;
} }
@ -718,10 +698,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
if (requestCode == RC_SETTINGS) if (requestCode == RC_SETTINGS)
{ {
File InstantSaveDir = new File(NativeExports.SettingsLoadString(SettingsID.Directory_InstantSave.getValue())); StartGameMenu(true);
final File GameSaveDir = new File(InstantSaveDir,NativeExports.SettingsLoadString(SettingsID.Game_UniqueSaveDir.getValue()));
StartGameMenu(GameSaveDir, true);
return; return;
} }
// Check which request we're responding to // Check which request we're responding to
@ -847,93 +824,19 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
} }
} }
public void ShowPaymentOptions() private boolean ShouldShowSupportWindow()
{ {
ArrayList<String> skuList = new ArrayList<String>(); Log.d("GalleryActivity", "ShowSupportWindow mHasSaveSupport = " + mHasSaveSupport);
skuList.add(SKU_PJ64SUPPORTOR_2); if (mHasSaveSupport)
skuList.add(SKU_PJ64SUPPORTOR_5); {
skuList.add(SKU_PJ64SUPPORTOR_8); return false;
skuList.add(SKU_PJ64SUPPORTOR_10); }
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList); Log.d("GalleryActivity", "ShowSupportWindow mPj64Supporter = " + mPj64Supporter);
if (mPj64Supporter)
final Context context = this;
final Activity activity = this;
IabHelper.QueryInventoryFinishedListener GotPaymentOptionListener = new IabHelper.QueryInventoryFinishedListener()
{
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
Log.d("GalleryActivity", "Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mIabHelper == null) return;
// Is it a failure?
if (result.isFailure())
{
//complain("Failed to query inventory: " + result);
return;
}
Log.d("GalleryActivity", "SKU_PJ64SUPPORTOR_2 price: " + inventory.getSkuDetails(SKU_PJ64SUPPORTOR_2).getPrice());
Log.d("GalleryActivity", "SKU_PJ64SUPPORTOR_5 price: " + inventory.getSkuDetails(SKU_PJ64SUPPORTOR_5).getPrice());
Log.d("GalleryActivity", "SKU_PJ64SUPPORTOR_8 price: " + inventory.getSkuDetails(SKU_PJ64SUPPORTOR_8).getPrice());
Log.d("GalleryActivity", "SKU_PJ64SUPPORTOR_10 price: " + inventory.getSkuDetails(SKU_PJ64SUPPORTOR_10).getPrice());
CharSequence options[] = new CharSequence[]
{
inventory.getSkuDetails(SKU_PJ64SUPPORTOR_10).getPrice(),
inventory.getSkuDetails(SKU_PJ64SUPPORTOR_8).getPrice(),
inventory.getSkuDetails(SKU_PJ64SUPPORTOR_5).getPrice(),
inventory.getSkuDetails(SKU_PJ64SUPPORTOR_2).getPrice()
};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select an amount");
builder.setItems(options, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
switch (which)
{
case 0: PurcahseProject64Support(activity,SKU_PJ64SUPPORTOR_10); break;
case 1: PurcahseProject64Support(activity,SKU_PJ64SUPPORTOR_8); break;
case 2: PurcahseProject64Support(activity,SKU_PJ64SUPPORTOR_5); break;
case 3: PurcahseProject64Support(activity,SKU_PJ64SUPPORTOR_2); break;
}
}
});
final AlertDialog dialog = builder.create();
dialog.setOnCancelListener(new OnCancelListener()
{
public void onCancel(DialogInterface dialog)
{
ShowSupportWindow();
}
});
dialog.show();
}
};
try
{
mIabHelper.queryInventoryAsync(true, skuList, null, GotPaymentOptionListener);
}
catch (IabAsyncInProgressException e)
{
e.printStackTrace();
}
}
public boolean ShouldShowSupportWindow()
{
Log.d("GalleryActivity", "ShowSupportWindow mShownSupportWindow = " + mShownSupportWindow);
if (!mShownSupportWindow)
{ {
return false; return false;
} }
mShownSupportWindow = false;
int RunCount = NativeExports.UISettingsLoadDword(UISettingID.SupportWindow_RunCount.getValue()); int RunCount = NativeExports.UISettingsLoadDword(UISettingID.SupportWindow_RunCount.getValue());
Log.d("GalleryActivity", "ShowSupportWindow RunCount = " + RunCount); Log.d("GalleryActivity", "ShowSupportWindow RunCount = " + RunCount);
@ -941,15 +844,10 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
{ {
return false; return false;
} }
NativeExports.UISettingsSaveDword(UISettingID.SupportWindow_RunCount.getValue(), RunCount + 1);
Log.d("GalleryActivity", "ShowSupportWindow Set RunCount to " + (RunCount + 1));
if (RunCount < 3) RunCount = NativeExports.UISettingsLoadDword(UISettingID.Game_RunCount.getValue());
{ Log.d("GalleryActivity", "ShowSupportWindow Game_RunCount = " + RunCount);
return false; if (RunCount < 5)
}
if (((RunCount - 5) % 3) != 0)
{ {
return false; return false;
} }
@ -958,10 +856,12 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
public void ShowSupportWindow() public void ShowSupportWindow()
{ {
int RunCount = NativeExports.UISettingsLoadDword(UISettingID.SupportWindow_RunCount.getValue()); final Context context = this;
final Activity activity = this;
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Support Project64"); builder.setTitle(getText(R.string.GetSaveSupport_title));
builder.setMessage("Project64 is a software package designed to emulate a Nintendo64 video game system on a Android device. This allows you to play real N64 software in much the same way as it would be on the original hardware system.\n\nIf you like Project64 and have gotten some value out of it then please support project64 as either a thank you, or your desire to see it continually improved."); builder.setMessage(getText(R.string.GetSaveSupport_message));
builder.setNeutralButton("Not now", null); builder.setNeutralButton("Not now", null);
builder.setNegativeButton("Support Project64", null); builder.setNegativeButton("Support Project64", null);
builder.setCancelable(false); builder.setCancelable(false);
@ -974,6 +874,7 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
public void onClick(View v) public void onClick(View v)
{ {
dialog.dismiss(); dialog.dismiss();
StartGameMenu(false);
} }
}); });
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener( new View.OnClickListener() dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener( new View.OnClickListener()
@ -981,34 +882,21 @@ public class GalleryActivity extends AppCompatActivity implements IabBroadcastLi
@Override @Override
public void onClick(View v) public void onClick(View v)
{ {
ShowPaymentOptions(); setWaitScreen(true);
//Purchase save support
try
{
String payload = NativeExports.appVersion();
mIabHelper.launchPurchaseFlow(activity, SKU_SAVESUPPORT, RC_REQUEST, mPurchaseFinishedListener, payload);
}
catch (IabAsyncInProgressException e)
{
setWaitScreen(false);
}
dialog.dismiss(); dialog.dismiss();
} }
}); });
dialog.setCanceledOnTouchOutside(false); dialog.setCanceledOnTouchOutside(false);
if (RunCount > 20)
{
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(false);
TimerTask task = new TimerTask()
{
@Override
public void run()
{
Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable()
{
public void run()
{
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(true);
}
});
}
};
final Timer timer = new Timer();
timer.schedule(task, 35 * 1000);
}
} }
public void launchGameActivity() public void launchGameActivity()