From 766ee2f0c574f1529fa22ee13ca4ddf5470bdf51 Mon Sep 17 00:00:00 2001 From: Trevor Siemens Date: Sat, 8 Feb 2014 15:35:57 -0800 Subject: [PATCH] Issue #13 - Actionbar title shows app name when nav drawer is out. settings menu item is shown as well. --- pathfinder-toolkit/res/menu/shared_menu.xml | 3 ++- .../pathfinder/toolkit/PTMainActivity.java | 18 +++++++++++------- .../toolkit/views/PTBasePageFragment.java | 8 +++++++- .../toolkit/views/PTDiceRollerFragment.java | 10 ++++++---- .../views/PTPointbuyCalculatorFragment.java | 12 ++++++++---- .../character/PTCharacterSheetFragment.java | 3 ++- .../party/PTInitiativeTrackerFragment.java | 14 +++++++++++--- .../views/party/PTPartyManagerFragment.java | 8 ++++++-- .../party/PTPartySkillCheckerFragment.java | 17 ++++++++++++----- 9 files changed, 65 insertions(+), 28 deletions(-) diff --git a/pathfinder-toolkit/res/menu/shared_menu.xml b/pathfinder-toolkit/res/menu/shared_menu.xml index a5e5611..3616ff1 100644 --- a/pathfinder-toolkit/res/menu/shared_menu.xml +++ b/pathfinder-toolkit/res/menu/shared_menu.xml @@ -3,5 +3,6 @@ + android:showAsAction="never" + android:orderInCategory="1000"/> diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/PTMainActivity.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/PTMainActivity.java index a835282..489b615 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/PTMainActivity.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/PTMainActivity.java @@ -2,12 +2,8 @@ import java.util.Calendar; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.FragmentManager; +import android.app.*; import android.app.FragmentManager.OnBackStackChangedListener; -import android.app.FragmentTransaction; -import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; @@ -132,11 +128,19 @@ private void setupNavDrawer() { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { + if (m_currentFragment != null) { + m_currentFragment.updateTitle(); + } invalidateOptionsMenu(); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { + ActionBar ab = getActionBar(); + if (ab != null) { + ab.setTitle(R.string.app_name); + ab.setSubtitle(null); + } invalidateOptionsMenu(); hideKeyboard(); } @@ -191,8 +195,8 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) { boolean drawerOpen = m_drawerLayout.isDrawerOpen(m_drawerList); for (int i = 0; i < menu.size(); i++) { - menu.getItem(i).setVisible(!drawerOpen); - + menu.getItem(i).setVisible(!drawerOpen + || menu.getItem(i).getItemId() == R.id.mi_app_settings); } return super.onPrepareOptionsMenu(menu); } diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTBasePageFragment.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTBasePageFragment.java index 4dc4f24..9d858c8 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTBasePageFragment.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTBasePageFragment.java @@ -10,7 +10,7 @@ import android.view.MenuItem; import android.view.View; -public class PTBasePageFragment extends Fragment{ +public abstract class PTBasePageFragment extends Fragment{ private View m_rootView; @@ -23,6 +23,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void onResume() { super.onResume(); + updateTitle(); Activity a = getActivity(); if (a instanceof PTMainActivity) { ((PTMainActivity) a).hideKeyboardDelayed(100); @@ -40,6 +41,11 @@ public void setTitle(int resId) { public void setSubtitle(String subtitle) { getActivity().getActionBar().setSubtitle(subtitle); } + + /** + * Sets the default title and subtitle for the fragment + */ + public abstract void updateTitle(); public View getRootView() { return m_rootView; diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTDiceRollerFragment.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTDiceRollerFragment.java index 21a933b..c0a7832 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTDiceRollerFragment.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTDiceRollerFragment.java @@ -47,8 +47,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRootView(inflater.inflate(R.layout.fragment_dice_roller, container, false)); - setTitle(R.string.title_activity_ptdice_roller); - setSubtitle(null); setupContent(); mRollMode = ROLLMODE_SINGLE; @@ -57,9 +55,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, return getRootView(); } + @Override + public void updateTitle() { + setTitle(R.string.title_activity_ptdice_roller); + setSubtitle(null); + } - - // Responds to roll type radio toggle buttons + // Responds to roll type radio toggle buttons public void rollTypeClicked(View view) { ToggleButton toggleButton = (ToggleButton) view; diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTPointbuyCalculatorFragment.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTPointbuyCalculatorFragment.java index 4a7c39e..2f13484 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTPointbuyCalculatorFragment.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/PTPointbuyCalculatorFragment.java @@ -89,8 +89,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRootView(inflater.inflate(R.layout.fragment_ability_calculator, container, false)); - setTitle(R.string.title_activity_ability_calc); - setSubtitle(null); m_isHuman = true; @@ -150,8 +148,14 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.pointbuy_menu, menu); super.onCreateOptionsMenu(menu, inflater); } - - private class RaceItemSelectedListener implements OnItemSelectedListener { + + @Override + public void updateTitle() { + setTitle(R.string.title_activity_ability_calc); + setSubtitle(null); + } + + private class RaceItemSelectedListener implements OnItemSelectedListener { @Override public void onItemSelected(AdapterView parent, View view, int pos, long id) { // An item was selected. You can retrieve the selected item using diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/character/PTCharacterSheetFragment.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/character/PTCharacterSheetFragment.java index 8b1202d..237d04d 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/character/PTCharacterSheetFragment.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/character/PTCharacterSheetFragment.java @@ -57,7 +57,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return super.onCreateView(inflater, container, savedInstanceState); } - + + @Override public void updateTitle() { setTitle(m_characterRepo.queryName(m_currentCharacterID)); setSubtitle(getFragmentTitle()); diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTInitiativeTrackerFragment.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTInitiativeTrackerFragment.java index fc8a652..4bec840 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTInitiativeTrackerFragment.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTInitiativeTrackerFragment.java @@ -62,7 +62,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRootView(inflater.inflate(R.layout.fragment_initiative_tracker, container, false)); - setTitle(R.string.title_activity_initiative_tracker); m_rollInitiativeButton = (Button) getRootView().findViewById(R.id.buttonRollInitiative); m_rollInitiativeButton.setOnClickListener(this); @@ -101,6 +100,16 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); } + @Override + public void updateTitle() { + setTitle(R.string.title_activity_initiative_tracker); + if (m_party != null) { + setSubtitle(m_party.getName()); + } else { + setSubtitle(null); + } + } + private void showPartyDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); @@ -227,8 +236,7 @@ private void refreshPartyView() { R.layout.party_roll_row, memberNames, memberRollValues, null); m_partyMemberList.setAdapter(adapter); m_rollInitiativeButton.setEnabled(!m_hasRolled); - setTitle(R.string.title_activity_initiative_tracker); - setSubtitle(m_party.getName()); + updateTitle(); } /** diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTPartyManagerFragment.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTPartyManagerFragment.java index 2a905ad..b41aac1 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTPartyManagerFragment.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTPartyManagerFragment.java @@ -64,8 +64,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, setRootView(inflater.inflate(R.layout.fragment_party_manager, container, false)); - setTitle(R.string.title_activity_party_manager); - setSubtitle(null); m_partyNameEditText = (EditText) getRootView() .findViewById(R.id.editTextPartyName); @@ -84,6 +82,12 @@ public void onPause() { super.onPause(); } + @Override + public void updateTitle() { + setTitle(R.string.title_activity_party_manager); + setSubtitle(null); + } + /** * Load the currently set party in shared prefs If there is no party set in * user prefs, it automatically generates a new one. diff --git a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTPartySkillCheckerFragment.java b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTPartySkillCheckerFragment.java index d580129..13b6d7b 100644 --- a/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTPartySkillCheckerFragment.java +++ b/pathfinder-toolkit/src/com/lateensoft/pathfinder/toolkit/views/party/PTPartySkillCheckerFragment.java @@ -48,9 +48,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRootView(inflater.inflate(R.layout.fragment_skill_checker, container, false)); - setTitle(R.string.title_activity_skill_checker); - setSubtitle(null); - + m_skillSelectedForRoll = 0; m_rollButton = (Button) getRootView().findViewById(R.id.buttonRoll); @@ -71,6 +69,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, return getRootView(); } + + @Override + public void updateTitle() { + setTitle(R.string.title_activity_skill_checker); + if (m_party != null) { + setSubtitle(m_party.getName()); + } else { + setSubtitle(null); + } + } /** * Load the current encounter party in shared prefs @@ -133,8 +141,7 @@ private void refreshPartyView(){ } PTPartyRollAdapter adapter = new PTPartyRollAdapter(getActivity(), R.layout.party_roll_row, memberNames, memberRollValues, critValues); m_partyMemberList.setAdapter(adapter); - setTitle(R.string.title_activity_skill_checker); - setSubtitle(m_party.getName()); + updateTitle(); } public void resetPartyRolls(){