From 0feee0b9404cd664b3c1a4fa752271d93c9f4e32 Mon Sep 17 00:00:00 2001 From: DjBushido Date: Wed, 16 Apr 2014 13:57:33 -0400 Subject: [PATCH] Split out the Nav Drawers between activities --- .../res/layout/activity_bible_viewer.xml | 2 +- MinimalBible/res/layout/activity_download.xml | 2 +- .../res/layout/fragment_navigation_drawer.xml | 2 +- ...java => BaseNavigationDrawerFragment.java} | 42 +++---------------- .../downloader/DownloadActivity.java | 8 ++-- .../downloader/DownloadNavDrawerFragment.java | 39 +++++++++++++++++ .../activities/viewer/BibleViewer.java | 8 ++-- .../viewer/ViewerNavDrawerFragment.java | 38 +++++++++++++++++ 8 files changed, 94 insertions(+), 47 deletions(-) rename MinimalBible/src/org/bspeice/minimalbible/activities/{NavigationDrawerFragment.java => BaseNavigationDrawerFragment.java} (88%) create mode 100644 MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadNavDrawerFragment.java create mode 100644 MinimalBible/src/org/bspeice/minimalbible/activities/viewer/ViewerNavDrawerFragment.java diff --git a/MinimalBible/res/layout/activity_bible_viewer.xml b/MinimalBible/res/layout/activity_bible_viewer.xml index a350125..923252a 100644 --- a/MinimalBible/res/layout/activity_bible_viewer.xml +++ b/MinimalBible/res/layout/activity_bible_viewer.xml @@ -32,7 +32,7 @@ diff --git a/MinimalBible/res/layout/fragment_navigation_drawer.xml b/MinimalBible/res/layout/fragment_navigation_drawer.xml index e63c6d4..e66b955 100644 --- a/MinimalBible/res/layout/fragment_navigation_drawer.xml +++ b/MinimalBible/res/layout/fragment_navigation_drawer.xml @@ -7,5 +7,5 @@ android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" - tools:context="org.bspeice.minimalbible.activities.NavigationDrawerFragment" /> + tools:context="org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment" /> diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/NavigationDrawerFragment.java b/MinimalBible/src/org/bspeice/minimalbible/activities/BaseNavigationDrawerFragment.java similarity index 88% rename from MinimalBible/src/org/bspeice/minimalbible/activities/NavigationDrawerFragment.java rename to MinimalBible/src/org/bspeice/minimalbible/activities/BaseNavigationDrawerFragment.java index b847259..e78fd3d 100644 --- a/MinimalBible/src/org/bspeice/minimalbible/activities/NavigationDrawerFragment.java +++ b/MinimalBible/src/org/bspeice/minimalbible/activities/BaseNavigationDrawerFragment.java @@ -34,7 +34,7 @@ import com.readystatesoftware.systembartint.SystemBarTintManager; * > design guidelines for a complete explanation of the behaviors * implemented here. */ -public class NavigationDrawerFragment extends Fragment { +public class BaseNavigationDrawerFragment extends Fragment { /** * Remember the position of the selected item. @@ -58,14 +58,14 @@ public class NavigationDrawerFragment extends Fragment { private ActionBarDrawerToggle mDrawerToggle; private DrawerLayout mDrawerLayout; - private ListView mDrawerListView; + protected ListView mDrawerListView; private View mFragmentContainerView; - private int mCurrentSelectedPosition = 0; + protected int mCurrentSelectedPosition = 0; private boolean mFromSavedInstanceState; private boolean mUserLearnedDrawer; - public NavigationDrawerFragment() { + public BaseNavigationDrawerFragment() { } @Override @@ -97,29 +97,6 @@ public class NavigationDrawerFragment extends Fragment { setHasOptionsMenu(true); } - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - mDrawerListView = (ListView) inflater.inflate( - R.layout.fragment_navigation_drawer, container, false); - mDrawerListView - .setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, - int position, long id) { - selectItem(position); - } - }); - mDrawerListView.setAdapter(new ArrayAdapter(getActionBar() - .getThemedContext(), android.R.layout.simple_list_item_1, - android.R.id.text1, new String[] { - getString(R.string.title_section1), - getString(R.string.title_section2), - getString(R.string.title_section3), })); - mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); - return mDrawerListView; - } - public boolean isDrawerOpen() { return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); @@ -214,7 +191,7 @@ public class NavigationDrawerFragment extends Fragment { mDrawerLayout.setDrawerListener(mDrawerToggle); } - private void selectItem(int position) { + public void selectItem(int position) { mCurrentSelectedPosition = position; if (mDrawerListView != null) { mDrawerListView.setItemChecked(position, true); @@ -275,13 +252,6 @@ public class NavigationDrawerFragment extends Fragment { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } - - if (item.getItemId() == R.id.action_example) { - Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT) - .show(); - return true; - } - return super.onOptionsItemSelected(item); } @@ -297,7 +267,7 @@ public class NavigationDrawerFragment extends Fragment { // actionBar.setTitle(R.string.app_name); } - private ActionBar getActionBar() { + protected ActionBar getActionBar() { return ((ActionBarActivity) getActivity()).getSupportActionBar(); } diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadActivity.java b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadActivity.java index 987bcd0..d636851 100644 --- a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadActivity.java +++ b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadActivity.java @@ -3,7 +3,7 @@ package org.bspeice.minimalbible.activities.downloader; import org.bspeice.minimalbible.MinimalBibleConstants; import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.activities.BaseActivity; -import org.bspeice.minimalbible.activities.NavigationDrawerFragment; +import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment; import android.app.Activity; import android.app.AlertDialog; @@ -23,13 +23,13 @@ import android.widget.TextView; import android.widget.Toast; public class DownloadActivity extends BaseActivity implements - NavigationDrawerFragment.NavigationDrawerCallbacks { + BaseNavigationDrawerFragment.NavigationDrawerCallbacks { /** * Fragment managing the behaviors, interactions and presentation of the * navigation drawer. */ - private NavigationDrawerFragment mNavigationDrawerFragment; + private DownloadNavDrawerFragment mNavigationDrawerFragment; /** * Used to store the last screen title. For use in @@ -42,7 +42,7 @@ public class DownloadActivity extends BaseActivity implements super.onCreate(savedInstanceState); setContentView(R.layout.activity_download); - mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() + mNavigationDrawerFragment = (DownloadNavDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadNavDrawerFragment.java b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadNavDrawerFragment.java new file mode 100644 index 0000000..511d0b7 --- /dev/null +++ b/MinimalBible/src/org/bspeice/minimalbible/activities/downloader/DownloadNavDrawerFragment.java @@ -0,0 +1,39 @@ +package org.bspeice.minimalbible.activities.downloader; + +import org.bspeice.minimalbible.R; +import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; + +public class DownloadNavDrawerFragment extends BaseNavigationDrawerFragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mDrawerListView = (ListView) inflater.inflate( + R.layout.fragment_navigation_drawer, container, false); + mDrawerListView + .setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, + int position, long id) { + selectItem(position); + } + }); + mDrawerListView.setAdapter(new ArrayAdapter(getActionBar() + .getThemedContext(), android.R.layout.simple_list_item_1, + android.R.id.text1, new String[] { + getString(R.string.title_section1), + getString(R.string.title_section2), + getString(R.string.title_section3), })); + mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); + return mDrawerListView; + } + +} diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/viewer/BibleViewer.java b/MinimalBible/src/org/bspeice/minimalbible/activities/viewer/BibleViewer.java index 20627e5..d415b9d 100644 --- a/MinimalBible/src/org/bspeice/minimalbible/activities/viewer/BibleViewer.java +++ b/MinimalBible/src/org/bspeice/minimalbible/activities/viewer/BibleViewer.java @@ -6,7 +6,7 @@ import org.bspeice.minimalbible.R.layout; import org.bspeice.minimalbible.R.menu; import org.bspeice.minimalbible.R.string; import org.bspeice.minimalbible.activities.BaseActivity; -import org.bspeice.minimalbible.activities.NavigationDrawerFragment; +import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment; import org.bspeice.minimalbible.activities.downloader.DownloadActivity; import android.app.Activity; @@ -28,13 +28,13 @@ import android.widget.TextView; import com.readystatesoftware.systembartint.SystemBarTintManager; public class BibleViewer extends BaseActivity implements - NavigationDrawerFragment.NavigationDrawerCallbacks { + BaseNavigationDrawerFragment.NavigationDrawerCallbacks { /** * Fragment managing the behaviors, interactions and presentation of the * navigation drawer. */ - private NavigationDrawerFragment mNavigationDrawerFragment; + private ViewerNavDrawerFragment mNavigationDrawerFragment; /** * Used to store the last screen title. For use in @@ -47,7 +47,7 @@ public class BibleViewer extends BaseActivity implements super.onCreate(savedInstanceState); setContentView(R.layout.activity_bible_viewer); - mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() + mNavigationDrawerFragment = (ViewerNavDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); diff --git a/MinimalBible/src/org/bspeice/minimalbible/activities/viewer/ViewerNavDrawerFragment.java b/MinimalBible/src/org/bspeice/minimalbible/activities/viewer/ViewerNavDrawerFragment.java new file mode 100644 index 0000000..2889f0e --- /dev/null +++ b/MinimalBible/src/org/bspeice/minimalbible/activities/viewer/ViewerNavDrawerFragment.java @@ -0,0 +1,38 @@ +package org.bspeice.minimalbible.activities.viewer; + +import org.bspeice.minimalbible.R; +import org.bspeice.minimalbible.activities.BaseNavigationDrawerFragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; + +public class ViewerNavDrawerFragment extends BaseNavigationDrawerFragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mDrawerListView = (ListView) inflater.inflate( + R.layout.fragment_navigation_drawer, container, false); + mDrawerListView + .setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, + int position, long id) { + selectItem(position); + } + }); + mDrawerListView.setAdapter(new ArrayAdapter(getActionBar() + .getThemedContext(), android.R.layout.simple_list_item_1, + android.R.id.text1, new String[] { + getString(R.string.title_section1), + getString(R.string.title_section2), + getString(R.string.title_section3)})); + mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); + return mDrawerListView; + } +}