Android Open Source - MythTrack Delete Hero Dialog






From Project

Back to project page MythTrack.

License

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.

Java Source Code

/**
 * DeleteHeroDialog confirms a user's choice to delete a hero.
 *//from   www . j a v  a  2s.  com
 * @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 - DeleteHeroDialog                                                                       //
////////////////////////////////////////////////////////////////////////////////////////////////////
public class DeleteHeroDialog extends DialogFragment
{
  // INTERFACES ////////////////////////////////////////////////////////////////////////////////////

  /** Interface for listener for when a hero is deleted.*/
  OnDeleteHeroConfirmationListener callback;
  public interface OnDeleteHeroConfirmationListener
  {
    public void onDeleteHeroConfirmed(long heroID);
  }

  // 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
    {
      callback = (OnDeleteHeroConfirmationListener) activity;
    }
    catch(ClassCastException exception)
    {
      throw new ClassCastException(activity.toString()
        + " must implement onDeleteHeroConfirmed");
    }
  }


  /**
   * Called when the dialog is to be created.
   * @param arguments Arguments for the dialog.
   * @return The created dialog.
   */
  @Override
  public Dialog onCreateDialog(Bundle arguments)
  {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // Set the title.
    builder.setTitle(R.string.deleteherodialog_title);
    // Set the message.
    String deleteMessage = getArguments().getString("name") + " - " +
      getArguments().getString("class") + " " + getString(R.string.deleteherodialog_message);
    builder.setMessage(deleteMessage);
    // Set up the "Delete" button and its action.
    builder.setPositiveButton(R.string.deleteherodialog_positive,
      new DialogInterface.OnClickListener()
      {
        /**
         * Handle the "Delete" button being clicked.
         * @param dialogInterface The dialog being handled.
         * @param button Which button was clicked.
         */
        @Override
        public void onClick(DialogInterface dialogInterface, int button)
        {
          // Delete the hero via the activity.
          callback.onDeleteHeroConfirmed(getArguments().getLong("id"));
        }
      });
    // Set up the "Cancel" button and its action.
    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();
  }

}




Java Source Code List

nolanjurgens.mythtrack.app.BuyItemDialog.java
nolanjurgens.mythtrack.app.CreateHeroDialog.java
nolanjurgens.mythtrack.app.DeleteHeroDialog.java
nolanjurgens.mythtrack.app.EquipmentInfoDialog.java
nolanjurgens.mythtrack.app.HeroDisplayFragment.java
nolanjurgens.mythtrack.app.HeroHelper.java
nolanjurgens.mythtrack.app.HeroList.java
nolanjurgens.mythtrack.app.HeroTrackerActivity.java
nolanjurgens.mythtrack.app.Hero.java
nolanjurgens.mythtrack.app.InventoryList.java
nolanjurgens.mythtrack.app.ItemHelper.java
nolanjurgens.mythtrack.app.ItemList.java
nolanjurgens.mythtrack.app.Item.java
nolanjurgens.mythtrack.app.MainActivity.java
nolanjurgens.mythtrack.app.RemoveItemDialog.java
nolanjurgens.mythtrack.app.SettingsActivity.java
nolanjurgens.mythtrack.app.SettingsFragment.java
nolanjurgens.mythtrack.app.StatInfoDialog.java
nolanjurgens.mythtrack.app.StatPickerDialog.java
nolanjurgens.mythtrack.app.TitleHelper.java
nolanjurgens.mythtrack.app.Title.java
nolanjurgens.mythtrack.provider.MythTrackBackup.java
nolanjurgens.mythtrack.provider.MythTrackContract.java
nolanjurgens.mythtrack.provider.MythTrackDatabase.java