Android Open Source - MythTrack Stat Info 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

/**
 * StatInfoDialog presents information about a given stat (or other tracked item).
 *//from   w  w  w  .  j a  v  a 2 s . co 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.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ScrollView;
import android.widget.TextView;

import nolanjurgens.mythtrack.R;
import nolanjurgens.mythtrack.provider.MythTrackContract;

////////////////////////////////////////////////////////////////////////////////////////////////////
// CLASS - StatInfoDialog                                                                         //
////////////////////////////////////////////////////////////////////////////////////////////////////
public class StatInfoDialog extends DialogFragment
{
  // CONSTANTS /////////////////////////////////////////////////////////////////////////////////////

  public static final int STAT_COURAGE = 1;
  public static final int STAT_GOLD = 2;
  public static final int STAT_MOVEMENT = 3;
  public static final int STAT_SERENDIPITY = 4;
  public static final int STAT_THREAT = 5;
  public static final int STAT_VITALITY = 6;
  public static final int STAT_POTIONS = 7;

  // METHODS ///////////////////////////////////////////////////////////////////////////////////////

  /**
   * Called when the fragment is attached to the activity.
   * @param activity The host activity.
   */
  @Override
  public void onAttach(Activity activity)
  {
    super.onAttach(activity);
  }


  /**
   * 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());
    LayoutInflater inflater = getActivity().getLayoutInflater();

    final int stat = getArguments().getInt("stat");

    // Set up the dialog.
    switch(stat)
    {
      case STAT_COURAGE:
      {
        // Set the title and icon.
        builder.setTitle(R.string.statinfodialog_courage_title);
        builder.setIcon(R.drawable.ic_stat_courage);

        // Build the dialog message view.
        ScrollView inputViews
          = (ScrollView) inflater.inflate(R.layout.fragment_stat_info_dialog_courage, null);
        String formatMessage = (String) getText(R.string.statinfodialog_courage_message_roll);
        int courage = getArguments().getInt("courage");
        if(courage < 0)
        {
          courage = 0;
        }
        String message = String.format(formatMessage, courage);
        final TextView textViewRoll
          = (TextView) inputViews.findViewById(R.id.statinfo_courage_roll);
        textViewRoll.setText(message);
        builder.setView(inputViews);
        break;
      }
      case STAT_GOLD:
      {
        // Set the title and icon.
        builder.setTitle(R.string.statinfodialog_gold_title);
        builder.setIcon(R.drawable.ic_stat_gold);

        // Build the dialog message view.
        ScrollView inputViews
          = (ScrollView) inflater.inflate(R.layout.fragment_stat_info_dialog_gold, null);
        builder.setView(inputViews);

        break;
      }
      case STAT_MOVEMENT:
      {
        // Set the title and icon.
        builder.setTitle(R.string.statinfodialog_movement_title);
        builder.setIcon(R.drawable.ic_stat_movement);

        // Build the dialog message view.
        ScrollView inputViews
          = (ScrollView) inflater.inflate(R.layout.fragment_stat_info_dialog_movement, null);
        int movement = getArguments().getInt("movement");
        final TextView textViewCautious
          = (TextView) inputViews.findViewById(R.id.statinfo_movement_cautious);
        String formatMessage = (String) getText(R.string.statinfodialog_movement_message_mp);
        String message;
        if(movement == 1)
        {
          message = (String) getText(R.string.statinfodialog_movement_message_na);
          textViewCautious.setText(message);
        }
        else
        {
          int cautiousMP = (movement / 2) + (movement % 2);
          cautiousMP += getArguments().getInt("cautious_movement");
          message = String.format(formatMessage, cautiousMP);
          textViewCautious.setText(message);
        }
        final TextView textViewNormal
          = (TextView) inputViews.findViewById(R.id.statinfo_movement_normal);
        message = String.format(formatMessage, movement);
        textViewNormal.setText(message);
        builder.setView(inputViews);
        break;
      }
      case STAT_POTIONS:
      {
        // Set the title and icon.
        builder.setTitle(R.string.statinfodialog_potions_title);
        builder.setIcon(R.drawable.ic_equipment_potions);

        // Build the dialog message view.
        ScrollView inputViews
          = (ScrollView) inflater.inflate(R.layout.fragment_stat_info_dialog_potions, null);
        builder.setView(inputViews);

        break;
      }
      case STAT_SERENDIPITY:
      {
        // Set the title and icon.
        builder.setTitle(R.string.statinfodialog_serendipity_title);
        builder.setIcon(R.drawable.ic_stat_serendipity);

        // Build the dialog message view.
        ScrollView inputViews
          = (ScrollView) inflater.inflate(R.layout.fragment_stat_info_dialog_serendipity, null);
        builder.setView(inputViews);

        break;
      }
      case STAT_THREAT:
      {
        // Set the title and icon.
        builder.setTitle(R.string.statinfodialog_threat_title);
        builder.setIcon(R.drawable.ic_stat_threat);

        // Build the dialog message view.
        ScrollView inputViews
          = (ScrollView) inflater.inflate(R.layout.fragment_stat_info_dialog_threat, null);
        // Threat level.
        String formatMessage = (String) getText(R.string.statinfodialog_threat_level);
        int threat = getArguments().getInt("threat");
        String message = String.format(formatMessage, threat);
        final TextView textViewLevel
          = (TextView) inputViews.findViewById(R.id.statinfo_threat_level);
        textViewLevel.setText(message);

        // Threat attribute.
        final TextView textViewAttribute
          = (TextView) inputViews.findViewById(R.id.statinfo_threat_attribute);
        String formatMessage2 = (String) getText(R.string.statinfodialog_threat_attribute);
        int classID = getArguments().getInt("class_id");
        String attribute = null;
        int classIcon = 0;
        switch(classID)
        {
          // Arcane
          case MythTrackContract.Heroes.APPRENTICE:
          {
            attribute = (String) getText(R.string.arcane);
            classIcon = R.drawable.ic_attribute_arcane;
            break;
          }
          // Faith
          case MythTrackContract.Heroes.ACOLYTE:
          case MythTrackContract.Heroes.SKALD:
          {
            attribute = (String) getText(R.string.faith);
            classIcon = R.drawable.ic_attribute_faith;
            break;
          }
          // Guile
          case MythTrackContract.Heroes.BRIGAND:
          case MythTrackContract.Heroes.TRICKSTER:
          {
            attribute = (String) getText(R.string.guile);
            classIcon = R.drawable.ic_attribute_guile;
            break;
          }
          // Nature
          case MythTrackContract.Heroes.ARCHER:
          case MythTrackContract.Heroes.DRUID:
          case MythTrackContract.Heroes.SPRIGGAN:
          {
            attribute = (String) getText(R.string.nature);
            classIcon = R.drawable.ic_attribute_nature;
            break;
          }
          // Rage
          case MythTrackContract.Heroes.SOLDIER:
          {
            attribute = (String) getText(R.string.rage);
            classIcon = R.drawable.ic_attribute_rage;
            break;
          }

        }
        message = String.format(formatMessage2, attribute);
        textViewAttribute.setText(message);

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        {
          textViewAttribute.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, classIcon, 0);
        }
        else
        {
          textViewAttribute.setCompoundDrawablesWithIntrinsicBounds(0, 0, classIcon, 0);
        }

        builder.setView(inputViews);
        break;
      }
      case STAT_VITALITY:
      {
        // Set the title and icon.
        builder.setTitle(R.string.statinfodialog_vitality_title);
        builder.setIcon(R.drawable.ic_stat_vitality);

        // Build the dialog message view.
        ScrollView inputViews
          = (ScrollView) inflater.inflate(R.layout.fragment_stat_info_dialog_vitality, null);
        // Current vitality.
        String formatMessage = (String) getText(R.string.statinfodialog_vitality_message_current);
        int vitality = getArguments().getInt("vitality");
        String message = String.format(formatMessage, vitality);
        final TextView textViewCurrent
          = (TextView) inputViews.findViewById(R.id.statinfo_vitality_current);
        textViewCurrent.setText(message);
        // Max vitality.
        formatMessage = (String) getText(R.string.statinfodialog_vitality_message_max);
        int maxVitality = getArguments().getInt("max_vitality");
        message = String.format(formatMessage, maxVitality);
        final TextView textViewMax
          = (TextView) inputViews.findViewById(R.id.statinfo_vitality_max);
        textViewMax.setText(message);
        // Resurrect vitality.
        formatMessage = (String) getText(R.string.statinfodialog_vitality_message_resurrect);
        int resurrectVitality = (maxVitality / 2) + (maxVitality % 2);
        message = String.format(formatMessage, resurrectVitality);
        final TextView textViewResurrect
          = (TextView) inputViews.findViewById(R.id.statinfo_vitality_resurrect);
        textViewResurrect.setText(message);
  
        builder.setView(inputViews);
        break;
      }
    }

    // Set up the "Dismiss" button and its action.
    builder.setPositiveButton(R.string.statinfodialog_dismiss, new DialogInterface.OnClickListener()
      {
        /**
         * Handle "Dismiss" button clicks.
         * @param dialogInterface The dialog that was clicked.
         * @param clickedButton Which button was clicked.
         */
        @Override
        public void onClick(DialogInterface dialogInterface, int clickedButton)
        {
          // Just dismiss the dialog.
        }
      }
    );

    // Create 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