public void showThemeMenu() { final ThemeManager themes = game.getThemeManager(); String[] themeMenuLabels = themes.getAvailableThemeLabels(); Integer[] themeMenuIcons = themes.getAvailableThemeIconImageIDs(); ListAdapter adapter = new ArrayAdapterWithIcons( this, android.R.layout.select_dialog_singlechoice, themeMenuLabels, themeMenuIcons); AlertDialog.Builder builder = getDialog(this); builder.setTitle("Themes Options"); builder.setPositiveButton("OK", null); builder.setSingleChoiceItems( adapter, themes.getCurrentThemeID(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { Log.d(LOGGER, "Theme Selected: " + item); if (themes.isAvailable(item)) { themes.setTheme(item); } else { purchaseItem(themes.getSkuForTheme(item)); } } }); builder.show(); }
@Override public void onIabPurchaseFinished(IabResult result, Purchase info) { ThemeManager themes = game.getThemeManager(); if (result.isFailure()) { Log.e(LOGGER, "Purchase failed: " + result); Toast.makeText(this, "In-App Purchase Failed or was cancelled.", Toast.LENGTH_LONG).show(); } else if (RANDOM_BOT_SKU.equals(info.getSku())) { Log.d(LOGGER, "Purchase of RandomBot succeeded."); purchaseRandomBot(); } else if (themes.purchaseTheme(info.getSku())) { Log.d(LOGGER, "Theme Purchased"); } }
@Override public void onQueryInventoryFinished(IabResult result, Inventory inv) { if (result.isSuccess()) { Log.d(LOGGER, "In app purchases query complete" + result); boolean randomBotPurchaseCheck = inv.hasPurchase(RANDOM_BOT_SKU); if (randomBotPurchaseCheck && !randomBotPurchased) { Log.d(LOGGER, "RandomBot Purchase Imported"); purchaseRandomBot(); } else if (!randomBotPurchaseCheck && randomBotPurchased) { Log.d(LOGGER, "RandomBot Refund Imported"); refundRandomBot(); } final ThemeManager themes = game.getThemeManager(); themes.importPurchases(inv); } else { Log.e(LOGGER, "In app purchases could not be verified."); } }
public void showPauseMenu() { String[] pausedMenuLabels = new String[7]; Integer[] pausedMenuIcons = new Integer[7]; pausedMenuLabels[0] = "GamePlay"; pausedMenuIcons[0] = game.getGameplayManager().getCurrentIconID(); pausedMenuLabels[1] = "Themes"; pausedMenuIcons[1] = game.getThemeManager().getCurrentThemeIconID(); if (randomBotPurchased) { pausedMenuLabels[2] = "Picture For RandomBot"; } else { pausedMenuLabels[2] = "Purchase RandomBot"; } pausedMenuIcons[2] = R.drawable.ic_action_action_android; if (game.isMute()) { pausedMenuLabels[3] = "Sound: Off"; pausedMenuIcons[3] = R.drawable.ic_action_av_volume_off; } else { pausedMenuLabels[3] = "Sound: On"; pausedMenuIcons[3] = R.drawable.ic_action_av_volume_up; } if (game.isBlackBackground()) { pausedMenuLabels[4] = "Background: Black"; pausedMenuIcons[4] = R.drawable.ic_action_action_favorite; } else { pausedMenuLabels[4] = "Background: Clear"; pausedMenuIcons[4] = R.drawable.ic_action_action_favorite_outline; } pausedMenuLabels[5] = "High Scores"; pausedMenuIcons[5] = R.drawable.ic_action_action_grade; pausedMenuLabels[6] = "Credits"; pausedMenuIcons[6] = R.drawable.ic_action_image_palette; ListAdapter adapter = new ArrayAdapterWithIcons( this, android.R.layout.select_dialog_item, pausedMenuLabels, pausedMenuIcons); AlertDialog.Builder builder = getDialog(this); builder.setTitle("Pause Menu"); builder.setPositiveButton( "Start New Game", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { Log.d(LOGGER, "Restart Button Clicked: Starting a new game"); game.startNewGame(true); } }); builder.setNegativeButton( "Continue Game", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { Log.d(LOGGER, "Continue Button Clicked: Continuing with current game"); game.resume(); } }); builder.setSingleChoiceItems( adapter, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (item == 0) { showGameplayMenu(); } else if (item == 1) { showThemeMenu(); } else if (item == 2) { if (randomBotPurchased) { showRandomBotMenu(); } else { showRandomBotPurchaseMenu(); } } else if (item == 3) { game.swapMute(); dialog.dismiss(); game.resume(); } else if (item == 4) { game.swapBlackBackground(); dialog.dismiss(); game.resume(); } else if (item == 5) { showHighScoreMenu(); } else if (item == 6) { showCreditScreen(); dialog.dismiss(); } Log.d(LOGGER, "MenuClick Detected!, item# " + item); } }); builder.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); game.resume(); } }); builder.show(); }