Back to project page MythTrack.
The source code is released under:
MIT License
If you think the Android project MythTrack listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * BuyItemDialog presents a dialog for the user confirm the purchase of an item. *//from w ww. ja va2 s .c o m * @author Nolan Jurgens */ package nolanjurgens.mythtrack.app; // IMPORTS ///////////////////////////////////////////////////////////////////////////////////////// import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; import android.os.Bundle; import nolanjurgens.mythtrack.R; //////////////////////////////////////////////////////////////////////////////////////////////////// // CLASS - BuyItemDialog // //////////////////////////////////////////////////////////////////////////////////////////////////// public class BuyItemDialog extends DialogFragment { // INTERFACES //////////////////////////////////////////////////////////////////////////////////// /** Interface for a listener for when an item is purchased.*/ OnItemBoughtListener itemBoughtCallback; public interface OnItemBoughtListener { public void onItemBought(long heroID, long itemID, int itemValue); } // METHODS /////////////////////////////////////////////////////////////////////////////////////// /** * Called when the fragment is attached to the activity. * @param activity The host activity. */ @Override public void onAttach(Activity activity) { super.onAttach(activity); // Make sure the host activity implements the interface. try { itemBoughtCallback = (OnItemBoughtListener) activity; } catch(ClassCastException exception) { throw new ClassCastException(activity.toString() + " must implement onItemBought"); } } /** * Called when the dialog is to be created. * @param arguments Arguments for the dialog. * @return The created dialog. */ @Override public Dialog onCreateDialog(Bundle arguments) { final long heroID = getArguments().getLong("hero_id"); final long itemID = getArguments().getLong("item_id"); final String itemName = getArguments().getString("item_name"); final int itemCost = getArguments().getInt("item_cost"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.itemlist_buy_title); String formatMessage = getResources().getString(R.string.itemlist_buy_message); String message = String.format(formatMessage, itemName, itemCost); builder.setMessage(message); // Set up the "Buy" button and its actions. builder.setPositiveButton(R.string.itemlist_buy_positive_button, new DialogInterface.OnClickListener() { /** * Handle the "Buy" button being clicked. * @param dialogInterface The dialog being handled. * @param button Which button was clicked. */ @Override public void onClick(DialogInterface dialogInterface, int button) { itemBoughtCallback.onItemBought(heroID, itemID, itemCost); } }); // Set up the "Cancel" button and its actions. builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { /** * Handle the "Cancel" button being clicked. * @param dialogInterface The dialog being handled. * @param button Which button was clicked. */ @Override public void onClick(DialogInterface dialogInterface, int button) { // Just exit the dialog. } }); return builder.create(); } }