Skip to content

Commit

Permalink
Fixed options menu in fragments to follow proper calling procedure, s…
Browse files Browse the repository at this point in the history
…o it is always updated. Updated gitignore to include IntelliJIDEA files.
  • Loading branch information
tsiemens committed Jan 28, 2014
1 parent 75743ac commit c42e5f2
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 83 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ local.properties

# PDT-specific
.buildpath

# IntelliJ files
.idea
*.iml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testQuery() {

public void testQueryList() {
List<Entry<Long, String>> names = m_repo.queryList();
assertEquals(names.get(0).getValue(), m_char1.getName());
assertEquals(names.get(1).getValue(), CHARACTER_NAME);
assertEquals(m_char1.getName(), names.get(0).getValue());
assertEquals(CHARACTER_NAME, names.get(1).getValue());
}
}
7 changes: 3 additions & 4 deletions pathfinder-toolkit/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
<string name="title_activity_party_manager">Party Manager</string>
<string name="title_activity_party_member_editor">Party Member Editor</string>
<string name="title_activity_settings">Settings</string>
<string name="auto_fill">Autofill</string>

<string name="autofill_toast_text">Character stats autofilled</string>


<string name="updating_dialog_message">Updating…</string>

<string name="main_menu_icons_description">Icon for main menu item</string>

<!-- Global menu item strings -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public class PTMainActivity extends Activity implements
private ActionBarDrawerToggle m_drawerToggle;
private ExpandableListView m_drawerList;

private OnBackStackChangedListener m_backstackListener;

private PTBasePageFragment m_currentFragment;
private long m_currentFragmentId = 0;

Expand All @@ -76,13 +74,6 @@ public void onCreate(Bundle savedInstanceState) {
}

setContentView(R.layout.activity_drawer_main);
m_backstackListener = new OnBackStackChangedListener() {

@Override public void onBackStackChanged() {
invalidateOptionsMenu();
}
};
getFragmentManager().addOnBackStackChangedListener(m_backstackListener);

setupNavDrawer();

Expand All @@ -95,7 +86,7 @@ public void onCreate(Bundle savedInstanceState) {
final ProgressDialog progDialog = new ProgressDialog(this);
progDialog.setCancelable(false);
progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDialog.setTitle("Updating...");
progDialog.setTitle(getString(R.string.updating_dialog_message));
progDialog.show();

PatcherTask task = new PatcherTask();
Expand Down Expand Up @@ -191,12 +182,8 @@ public void showRateAppPromptDialog() {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (m_currentFragment != null) {
m_currentFragment.onCreateOptionsMenu(menu);
}

// Add menu items which are visible for all fragments
PTSharedMenu.onCreateOptionsMenu(menu, this);
PTSharedMenu.onCreateOptionsMenu(menu, getMenuInflater());
return true;
}

Expand All @@ -220,16 +207,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

if (PTSharedMenu.onOptionsItemSelected(item, this) == false) {
if (m_currentFragment != null) {
m_currentFragment.onOptionsItemSelected(item);
}
}

PTSharedMenu.onOptionsItemSelected(item, this);
return super.onOptionsItemSelected(item);
}

// For dialog
@Override
public void onClick(DialogInterface dialogInterface, int selection) {
PTSharedPreferences sharedPrefs = PTSharedPreferences.getInstance();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lateensoft.pathfinder.toolkit;

import android.view.MenuInflater;
import com.lateensoft.pathfinder.toolkit.views.settings.PTSettingsActivity;

import android.app.Activity;
Expand All @@ -9,8 +10,8 @@

public class PTSharedMenu {

public static void onCreateOptionsMenu(Menu menu, Activity activity) {
activity.getMenuInflater().inflate(R.menu.shared_menu, menu);
public static void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.shared_menu, menu);
}

public static boolean onOptionsItemSelected(MenuItem item, Activity activity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lateensoft.pathfinder.toolkit.views;

import android.os.Bundle;
import com.lateensoft.pathfinder.toolkit.PTMainActivity;

import android.app.Activity;
Expand All @@ -13,23 +14,21 @@ public class PTBasePageFragment extends Fragment{

private View m_rootView;

@Override
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}

@Override
public void onResume() {
super.onResume();
Activity a = getActivity();
if (a instanceof PTMainActivity) {
((PTMainActivity) a).hideKeyboardDelayed(100);
}
}

public boolean onCreateOptionsMenu(Menu menu) {
return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
return false;
}


public void setTitle(String title) {
getActivity().getActionBar().setTitle(title);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

return getRootView();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if (inflater != null) {
inflater.inflate(R.menu.pointbuy_menu, menu);
}

super.onCreateOptionsMenu(menu);
return true;
}

@Override
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 onItemSelected(AdapterView<?> parent, View view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if (inflater != null) {
inflater.inflate(R.menu.character_sheet_menu, menu);
}

super.onCreateOptionsMenu(menu);
return true;
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.character_sheet_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}

private void showCharacterDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,13 @@ public boolean onOptionsItemSelected(MenuItem item) {

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if (inflater != null) {
inflater.inflate(R.menu.initiative_tracker_menu, menu);
}

super.onCreateOptionsMenu(menu);
return true;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.initiative_tracker_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}

private void showPartyDialog() {
private void showPartyDialog() {

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

Expand Down Expand Up @@ -237,9 +232,7 @@ private void refreshPartyView() {

/**
* launches the party member editor
*
* @param index
* (the actual index, not the roll value index)
* @param member the member to send to the editor
*/
private void showPartyMemberEditor(PTPartyMember member) {
Intent intent = new Intent(getActivity(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,13 @@ public boolean onOptionsItemSelected(MenuItem item) {

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if (inflater != null) {
inflater.inflate(R.menu.party_manager_menu, menu);
}

super.onCreateOptionsMenu(menu);
return true;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.party_manager_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}

private void showPartyDialog() {
private void showPartyDialog() {
m_partyIDSelectedInDialog = m_party.getID(); // actual current party

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Expand Down

0 comments on commit c42e5f2

Please sign in to comment.