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.
/** * EquipmentInfoDialog presents dice bonuses and other important stats from the equipped items. *//w w w .j a v a 2 s. c o m * @author Nolan Jurgens */ package nolanjurgens.mythtrack.app; // IMPORTS ///////////////////////////////////////////////////////////////////////////////////////// import android.app.ActionBar; import android.app.Activity; import android.app.DialogFragment; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.TextView; import nolanjurgens.mythtrack.R; import nolanjurgens.mythtrack.provider.MythTrackContract; //////////////////////////////////////////////////////////////////////////////////////////////////// // CLASS - EquipmentInfoDialog // //////////////////////////////////////////////////////////////////////////////////////////////////// public class EquipmentInfoDialog extends DialogFragment { // INTERFACES //////////////////////////////////////////////////////////////////////////////////// /** Interface for a listener for when the hero is requested.*/ OnHeroRequestedListener requestedCallback; public interface OnHeroRequestedListener { public Hero onHeroRequested(); } // METHODS /////////////////////////////////////////////////////////////////////////////////////// /** * Determines if the activity is running in dual pane mode. * @return True if the activity is in dual pane mode. */ public boolean checkForDualPaneMode() { // See if the dedicated HeroDisplay container is present and visible. View heroDisplayContainer = getActivity().findViewById(R.id.herotracker_herodisplay_container); return (heroDisplayContainer != null && heroDisplayContainer.getVisibility() == View.VISIBLE); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if(!checkForDualPaneMode()) { // If in single pane mode, set the icon. getDialog().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_stat_equipment); // Set the dialog to go away when the "Dismiss" button is pressed. getDialog().findViewById(R.id.equipmentinfodialog_button).setOnClickListener( new View.OnClickListener() { public void onClick(View view) { dismiss(); } } ); } else { // If in dual pane mode, remove the button. getActivity().findViewById(R.id.equipmentinfodialog_button).setVisibility(View.GONE); } } /** * 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 interfaces. try { requestedCallback = (OnHeroRequestedListener) activity; } catch(ClassCastException exception) { throw new ClassCastException(activity.toString() + " must implement onEquipmentRequested"); } } /** * Called when the fragment is about to be drawn for the first time. * @param inflater The layout inflater. * @param container The fragment container from the activity layout. * @param savedInstanceState Saved instance information. * @return The root view of the fragment. */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Set the subtitle ActionBar actionBar = getActivity().getActionBar(); if(actionBar != null) { if(checkForDualPaneMode()) { // In dual pane mode set a subtitle. getActivity().getActionBar().setSubtitle(R.string.equipmentinfodialog_title); } else { // In single pane mode set the dialog title and icon placement. getDialog().setTitle(R.string.equipmentinfodialog_title); getDialog().requestWindowFeature(Window.FEATURE_LEFT_ICON); } } // Inflate the view. View view = inflater.inflate(R.layout.fragment_equipment_info_dialog, container, false); // Try to load the view with the hero's equipment information. loadView(view); return view; } private void loadView(View view) { // Get the loaded hero so that their equipment info can be loaded into the view. Hero hero = requestedCallback.onHeroRequested(); if(hero == null) { return; } // Load the non-combat action modifier. if(hero.getNonCombatActionModifier() != 0) { TextView nonCombatActionText = (TextView) view.findViewById(R.id.equipmentinfodialog_non_combat_actions); String nonCombatActionFormat = getString(R.string.equipmentinfodialog_nca); nonCombatActionText.setText(String.format(nonCombatActionFormat, hero.getNonCombatActionModifier())); nonCombatActionText.setVisibility(View.VISIBLE); } // Load the hero's primary item info. Item primary = hero.getPrimaryItem(); TextView primaryName = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_name); primaryName.setText(primary.getName()); if(primary.getHitDiceModifier() != 0) { TextView primaryHit = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_hit_dice); primaryHit.setText("+" + primary.getHitDiceModifier()); } if(primary.getFateDiceModifier() != 0) { TextView primaryFate = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_fate_dice); primaryFate.setText("+" + primary.getFateDiceModifier()); } if(primary.getOffenseModifier() != 0) { TextView primaryOffense = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_offense); primaryOffense.setText("+" + primary.getOffenseModifier()); } if(primary.getDefenseModifier() != 0) { TextView primaryDefense = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_defense); primaryDefense.setText("+" + primary.getDefenseModifier()); } if(primary.getRange() != 0) { TextView primaryRange = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_range); String rangeFormat = getString(R.string.equipmentinfodialog_range); primaryRange.setText(String.format(rangeFormat, primary.getRange())); primaryRange.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ACOLYTE && primary.getFaithModifier() != 0) { TextView primaryFaith = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_faith); String faithFormat = getString(R.string.equipmentinfodialog_faith); primaryFaith.setText(String.format(faithFormat, primary.getFaithModifier())); primaryFaith.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ARCHER && primary.getAmmoCapacity() != 0) { TextView primaryAmmo = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_ammo); String ammoFormat = getString(R.string.equipmentinfodialog_ammo); primaryAmmo.setText(String.format(ammoFormat, primary.getAmmoCapacity())); primaryAmmo.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.SOLDIER && primary.getRageModifier() != 0) { TextView primaryRage = (TextView) view.findViewById(R.id.equipmentinfodialog_primary_rage); String rageFormat = getString(R.string.equipmentinfodialog_rage); primaryRage.setText(String.format(rageFormat, primary.getRageModifier())); primaryRage.setVisibility(View.VISIBLE); } // Load the hero's secondary item info. Item secondary = hero.getSecondaryItem(); TextView secondaryName = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_name); secondaryName.setText(secondary.getName()); // Item type icon that will be used if icons are switched. int typeIcon = R.drawable.ic_equipment_secondary; // Determine if the item is a two-handed primary/secondary or normal secondary. if(secondary.getType() == MythTrackContract.Items.TWO_HANDED) { // Use the two-handed icon. typeIcon = R.drawable.ic_equipment_two_handed; // Hide the primary item. view.findViewById(R.id.equipmentinfodialog_primary_name).setVisibility(View.GONE); view.findViewById(R.id.equipmentinfodialog_primary_stats_1).setVisibility(View.GONE); view.findViewById(R.id.equipmentinfodialog_primary_stats_2).setVisibility(View.GONE); } // Display Relic icon if it's a relic item and the hero is an acolyte. if(secondary.getCasting() == MythTrackContract.Items.RELIC && hero.getClassID() == MythTrackContract.Heroes.ACOLYTE) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { secondaryName.setCompoundDrawablesRelativeWithIntrinsicBounds(typeIcon, 0, R.drawable.ic_casting_relic, 0); } else { secondaryName.setCompoundDrawablesWithIntrinsicBounds(typeIcon, 0, R.drawable.ic_casting_relic, 0); } } // Display Focus icon if it's a focus item and the hero is an apprentice. else if(secondary.getCasting() == MythTrackContract.Items.FOCUS && hero.getClassID() == MythTrackContract.Heroes.APPRENTICE) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { secondaryName.setCompoundDrawablesRelativeWithIntrinsicBounds(typeIcon, 0, R.drawable.ic_casting_focus, 0); } else { secondaryName.setCompoundDrawablesWithIntrinsicBounds(typeIcon, 0, R.drawable.ic_casting_focus, 0); } } // Else just set the item type icon. else { // Set the type icon. if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { secondaryName.setCompoundDrawablesRelativeWithIntrinsicBounds(typeIcon, 0, 0, 0); } else { secondaryName.setCompoundDrawablesWithIntrinsicBounds(typeIcon, 0, 0, 0); } } if(secondary.getHitDiceModifier() != 0) { TextView secondaryHit = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_hit_dice); secondaryHit.setText("+" + secondary.getHitDiceModifier()); } if(secondary.getFateDiceModifier() != 0) { TextView secondaryFate = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_fate_dice); secondaryFate.setText("+" + secondary.getFateDiceModifier()); } if(secondary.getOffenseModifier() != 0) { TextView secondaryOffense = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_offense); secondaryOffense.setText("+" + secondary.getOffenseModifier()); } if(secondary.getDefenseModifier() != 0) { TextView secondaryDefense = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_defense); secondaryDefense.setText("+" + secondary.getDefenseModifier()); } if(secondary.getRange() != 0) { TextView secondaryRange = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_range); String rangeFormat = getString(R.string.equipmentinfodialog_range); secondaryRange.setText(String.format(rangeFormat, secondary.getRange())); secondaryRange.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ACOLYTE && secondary.getFaithModifier() != 0) { TextView secondaryFaith = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_faith); String faithFormat = getString(R.string.equipmentinfodialog_faith); secondaryFaith.setText(String.format(faithFormat, secondary.getFaithModifier())); secondaryFaith.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ARCHER && secondary.getAmmoCapacity() != 0) { TextView secondaryAmmo = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_ammo); String ammoFormat = getString(R.string.equipmentinfodialog_ammo); secondaryAmmo.setText(String.format(ammoFormat, secondary.getAmmoCapacity())); secondaryAmmo.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.SOLDIER && secondary.getRageModifier() != 0) { TextView secondaryRage = (TextView) view.findViewById(R.id.equipmentinfodialog_secondary_rage); String rageFormat = getString(R.string.equipmentinfodialog_rage); secondaryRage.setText(String.format(rageFormat, secondary.getRageModifier())); secondaryRage.setVisibility(View.VISIBLE); } // Load the hero's armor item info. Item armor = hero.getArmorItem(); TextView armorName = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_name); armorName.setText(armor.getName()); if(armor.getHitDiceModifier() != 0) { TextView armorHit = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_hit_dice); armorHit.setText("+" + armor.getHitDiceModifier()); } if(armor.getFateDiceModifier() != 0) { TextView armorFate = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_fate_dice); armorFate.setText("+" + armor.getFateDiceModifier()); } if(armor.getOffenseModifier() != 0) { TextView armorOffense = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_offense); armorOffense.setText("+" + armor.getOffenseModifier()); } if(armor.getDefenseModifier() != 0) { TextView armorDefense = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_defense); armorDefense.setText("+" + armor.getDefenseModifier()); } if(armor.getRange() != 0) { TextView armorRange = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_range); String rangeFormat = getString(R.string.equipmentinfodialog_range); armorRange.setText(String.format(rangeFormat, armor.getRange())); armorRange.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ACOLYTE && armor.getFaithModifier() != 0) { TextView armorFaith = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_faith); String faithFormat = getString(R.string.equipmentinfodialog_faith); armorFaith.setText(String.format(faithFormat, armor.getFaithModifier())); armorFaith.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ARCHER && armor.getAmmoCapacity() != 0) { TextView armorAmmo = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_ammo); String ammoFormat = getString(R.string.equipmentinfodialog_ammo); armorAmmo.setText(String.format(ammoFormat, armor.getAmmoCapacity())); armorAmmo.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.SOLDIER && armor.getRageModifier() != 0) { TextView armorRage = (TextView) view.findViewById(R.id.equipmentinfodialog_armor_rage); String rageFormat = getString(R.string.equipmentinfodialog_rage); armorRage.setText(String.format(rageFormat, armor.getRageModifier())); armorRage.setVisibility(View.VISIBLE); } // Load the hero's helm item info. Item helm = hero.getHelmItem(); TextView helmName = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_name); helmName.setText(helm.getName()); if(helm.getHitDiceModifier() != 0) { TextView helmHit = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_hit_dice); helmHit.setText("+" + helm.getHitDiceModifier()); } if(helm.getFateDiceModifier() != 0) { TextView helmFate = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_fate_dice); helmFate.setText("+" + helm.getFateDiceModifier()); } if(helm.getOffenseModifier() != 0) { TextView helmOffense = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_offense); helmOffense.setText("+" + helm.getOffenseModifier()); } if(helm.getDefenseModifier() != 0) { TextView helmDefense = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_defense); helmDefense.setText("+" + helm.getDefenseModifier()); } if(helm.getRange() != 0) { TextView helmRange = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_range); String rangeFormat = getString(R.string.equipmentinfodialog_range); helmRange.setText(String.format(rangeFormat, helm.getRange())); helmRange.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ACOLYTE && helm.getFaithModifier() != 0) { TextView helmFaith = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_faith); String faithFormat = getString(R.string.equipmentinfodialog_faith); helmFaith.setText(String.format(faithFormat, helm.getFaithModifier())); helmFaith.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ARCHER && helm.getAmmoCapacity() != 0) { TextView helmAmmo = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_ammo); String ammoFormat = getString(R.string.equipmentinfodialog_ammo); helmAmmo.setText(String.format(ammoFormat, helm.getAmmoCapacity())); helmAmmo.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.SOLDIER && helm.getRageModifier() != 0) { TextView helmRage = (TextView) view.findViewById(R.id.equipmentinfodialog_helm_rage); String rageFormat = getString(R.string.equipmentinfodialog_rage); helmRage.setText(String.format(rageFormat, helm.getRageModifier())); helmRage.setVisibility(View.VISIBLE); } // Load the hero's accessory item info. Item accessory = hero.getAccessoryItem(); TextView accessoryName = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_name); accessoryName.setText(accessory.getName()); if(accessory.getHitDiceModifier() != 0) { TextView accessoryHit = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_hit_dice); accessoryHit.setText("+" + accessory.getHitDiceModifier()); } if(accessory.getFateDiceModifier() != 0) { TextView accessoryFate = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_fate_dice); accessoryFate.setText("+" + accessory.getFateDiceModifier()); } if(accessory.getOffenseModifier() != 0) { TextView accessoryOffense = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_offense); accessoryOffense.setText("+" + accessory.getOffenseModifier()); } if(accessory.getDefenseModifier() != 0) { TextView accessoryDefense = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_defense); accessoryDefense.setText("+" + accessory.getDefenseModifier()); } if(accessory.getRange() != 0) { TextView accessoryRange = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_range); String rangeFormat = getString(R.string.equipmentinfodialog_range); accessoryRange.setText(String.format(rangeFormat, accessory.getRange())); accessoryRange.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ACOLYTE && accessory.getFaithModifier() != 0) { TextView accessoryFaith = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_faith); String faithFormat = getString(R.string.equipmentinfodialog_faith); accessoryFaith.setText(String.format(faithFormat, accessory.getFaithModifier())); accessoryFaith.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.ARCHER && accessory.getAmmoCapacity() != 0) { TextView accessoryAmmo = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_ammo); String ammoFormat = getString(R.string.equipmentinfodialog_ammo); accessoryAmmo.setText(String.format(ammoFormat, accessory.getAmmoCapacity())); accessoryAmmo.setVisibility(View.VISIBLE); } if(hero.getClassID() == MythTrackContract.Heroes.SOLDIER && accessory.getRageModifier() != 0) { TextView accessoryRage = (TextView) view.findViewById(R.id.equipmentinfodialog_accessory_rage); String rageFormat = getString(R.string.equipmentinfodialog_rage); accessoryRage.setText(String.format(rageFormat, accessory.getRageModifier())); accessoryRage.setVisibility(View.VISIBLE); } } public void refreshView() { View view = getView(); if(view != null) { loadView(view); } } }