diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9fb401f..d119e32 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ TabsViewPagerFragmentActivity class implements the Fragment activity that maintains a TabHost using a ViewPager. - * @author mwho + * The Display class implements the Fragment activity that maintains a TabHost using a ViewPager. */ -public class TabsViewPagerFragmentActivity extends FragmentActivity implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener { +public class Display extends ActionBarActivity implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener { private TabHost mTabHost; private ViewPager mViewPager; - private HashMap mapTabInfo = new HashMap(); + private HashMap mapTabInfo = new HashMap(); private PagerAdapter mPagerAdapter; /** * - * @author mwho * Maintains extrinsic info of a tab's construct */ private class TabInfo { @@ -42,7 +44,6 @@ public class TabsViewPagerFragmentActivity extends FragmentActivity implements T } /** * A simple factory that returns dummy views to the Tabhost - * @author mwho */ class TabFactory implements TabContentFactory { @@ -72,16 +73,47 @@ public class TabsViewPagerFragmentActivity extends FragmentActivity implements T protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate the layout - setContentView(R.layout.tabs_viewpager_layout); + setContentView(R.layout.display); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + toolbar.setTitle("Kauron"); + toolbar.setSubtitle("Brujo Tiflin"); + setSupportActionBar(toolbar); + getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true); // Initialise the TabHost this.initialiseTabHost(savedInstanceState); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state } - // Intialise ViewPager + // Initialise ViewPager this.intialiseViewPager(); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + if ( mTabHost.getCurrentTabTag().equals("Stats") ) { + getMenuInflater().inflate(R.menu.menu_welcome, menu); + } else if ( mTabHost.getCurrentTabTag().equals("Powers") ) { + getMenuInflater().inflate(R.menu.menu_show_player, menu); + } + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if ( id == R.id.action_add_player ) { + Toast.makeText(getApplicationContext(), "it works", Toast.LENGTH_LONG).show(); + } + + return super.onOptionsItemSelected(item); + } + /** (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle) */ @@ -96,9 +128,8 @@ public class TabsViewPagerFragmentActivity extends FragmentActivity implements T private void intialiseViewPager() { List fragments = new Vector<>(); - fragments.add(Fragment.instantiate(this, ShowPlayer.class.getName())); - fragments.add(Fragment.instantiate(this, PowerEditor.class.getName())); - fragments.add(Fragment.instantiate(this, PlayerEditor.class.getName())); + fragments.add(Fragment.instantiate(this, PlayerDisplay.class.getName())); + fragments.add(Fragment.instantiate(this, PowerDisplay.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); // this.mViewPager = (ViewPager)super.findViewById(R.id.viewpager); @@ -113,11 +144,9 @@ public class TabsViewPagerFragmentActivity extends FragmentActivity implements T mTabHost = (TabHost)findViewById(android.R.id.tabhost); mTabHost.setup(); TabInfo tabInfo = null; - TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Tab 1"), ( tabInfo = new TabInfo("Tab1", ShowPlayer.class, args))); + Display.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Stats").setIndicator("Stats"), (tabInfo = new TabInfo("Stats", PlayerDisplay.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); - TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Tab 2"), ( tabInfo = new TabInfo("Tab2", PowerEditor.class, args))); - this.mapTabInfo.put(tabInfo.tag, tabInfo); - TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("Tab 3"), ( tabInfo = new TabInfo("Tab3", PlayerEditor.class, args))); + Display.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Powers").setIndicator("Powers"), (tabInfo = new TabInfo("Powers", PowerDisplay.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); // Default to first tab //this.onTabChanged("Tab1"); @@ -131,7 +160,7 @@ public class TabsViewPagerFragmentActivity extends FragmentActivity implements T * @param tabHost * @param tabSpec */ - private static void AddTab(TabsViewPagerFragmentActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { + private static void AddTab(Display activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { // Attach a Tab view factory to the spec tabSpec.setContent(activity.new TabFactory(activity)); tabHost.addTab(tabSpec); diff --git a/app/src/main/java/com/kauron/dungeonmanager/PlayerDisplay.java b/app/src/main/java/com/kauron/dungeonmanager/PlayerDisplay.java new file mode 100644 index 0000000..4df8844 --- /dev/null +++ b/app/src/main/java/com/kauron/dungeonmanager/PlayerDisplay.java @@ -0,0 +1,28 @@ +package com.kauron.dungeonmanager; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +public class PlayerDisplay extends Fragment { + /** (non-Javadoc) + * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) + */ + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + if (container == null) { + // We have different layouts, and in one of them this + // fragment's containing frame doesn't exist. The fragment + // may still be created from its saved state, but there is + // no reason to try to create its view hierarchy because it + // won't be displayed. Note this is not needed -- we could + // just run the code below, where we would create and return + // the view hierarchy; it would just never be used. + return null; + } + return (LinearLayout) inflater.inflate(R.layout.fragment_player_display, container, false); + } +} diff --git a/app/src/main/java/com/kauron/dungeonmanager/PowerDisplay.java b/app/src/main/java/com/kauron/dungeonmanager/PowerDisplay.java new file mode 100644 index 0000000..822174f --- /dev/null +++ b/app/src/main/java/com/kauron/dungeonmanager/PowerDisplay.java @@ -0,0 +1,28 @@ +package com.kauron.dungeonmanager; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +public class PowerDisplay extends Fragment { + /** (non-Javadoc) + * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) + */ + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + if (container == null) { + // We have different layouts, and in one of them this + // fragment's containing frame doesn't exist. The fragment + // may still be created from its saved state, but there is + // no reason to try to create its view hierarchy because it + // won't be displayed. Note this is not needed -- we could + // just run the code below, where we would create and return + // the view hierarchy; it would just never be used. + return null; + } + return (LinearLayout) inflater.inflate(R.layout.fragment_power_display, container, false); + } +} diff --git a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java index af9914c..fabd88b 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/Welcome.java +++ b/app/src/main/java/com/kauron/dungeonmanager/Welcome.java @@ -166,7 +166,7 @@ public class Welcome extends ActionBarActivity { //TODO: export as files /**TEMP*/ startActivity(new Intent( - getApplicationContext(), TabsViewPagerFragmentActivity.class + getApplicationContext(), Display.class ).putExtra("player", position)); Toast.makeText( activity, "Exporting feature not implemented yet", Toast.LENGTH_LONG) diff --git a/app/src/main/res/layout/tabs_viewpager_layout.xml b/app/src/main/res/layout/display.xml similarity index 68% rename from app/src/main/res/layout/tabs_viewpager_layout.xml rename to app/src/main/res/layout/display.xml index 0cdd38f..bf8269d 100644 --- a/app/src/main/res/layout/tabs_viewpager_layout.xml +++ b/app/src/main/res/layout/display.xml @@ -1,9 +1,19 @@ - + + + diff --git a/app/src/main/res/layout/fragment_player_display.xml b/app/src/main/res/layout/fragment_player_display.xml new file mode 100644 index 0000000..66f1f9e --- /dev/null +++ b/app/src/main/res/layout/fragment_player_display.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_power_display.xml b/app/src/main/res/layout/fragment_power_display.xml new file mode 100644 index 0000000..812dca8 --- /dev/null +++ b/app/src/main/res/layout/fragment_power_display.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/stats_dialog.xml b/app/src/main/res/layout/stats_dialog.xml index c28c52c..5134fc7 100644 --- a/app/src/main/res/layout/stats_dialog.xml +++ b/app/src/main/res/layout/stats_dialog.xml @@ -10,8 +10,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" - android:orientation="vertical" - android:visibility="gone"> + android:orientation="vertical"> -