(
101 | getActionBar().getThemedContext(),
102 | android.R.layout.simple_list_item_activated_1,
103 | android.R.id.text1,
104 | new String[]{
105 | getString(R.string.title_section1),
106 | getString(R.string.title_section2),
107 | getString(R.string.title_section3),
108 | }));
109 | mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
110 | return mDrawerListView;
111 | }
112 |
113 | public boolean isDrawerOpen() {
114 | return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
115 | }
116 |
117 | /**
118 | * Users of this fragment must call this method to set up the navigation drawer interactions.
119 | *
120 | * @param fragmentId The android:id of this fragment in its activity's layout.
121 | * @param drawerLayout The DrawerLayout containing this fragment's UI.
122 | */
123 | public void setUp(int fragmentId, DrawerLayout drawerLayout) {
124 | mFragmentContainerView = getActivity().findViewById(fragmentId);
125 | mDrawerLayout = drawerLayout;
126 |
127 | // set a custom shadow that overlays the main content when the drawer opens
128 | mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
129 | // set up the drawer's list view with items and click listener
130 |
131 | ActionBar actionBar = getActionBar();
132 | actionBar.setDisplayHomeAsUpEnabled(true);
133 | actionBar.setHomeButtonEnabled(true);
134 |
135 | // ActionBarDrawerToggle ties together the the proper interactions
136 | // between the navigation drawer and the action bar app icon.
137 | mDrawerToggle = new ActionBarDrawerToggle(
138 | getActivity(), /* host Activity */
139 | mDrawerLayout, /* DrawerLayout object */
140 | R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
141 | R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
142 | R.string.navigation_drawer_close /* "close drawer" description for accessibility */
143 | ) {
144 | @Override
145 | public void onDrawerClosed(View drawerView) {
146 | super.onDrawerClosed(drawerView);
147 | if (!isAdded()) {
148 | return;
149 | }
150 |
151 | getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
152 | }
153 |
154 | @Override
155 | public void onDrawerOpened(View drawerView) {
156 | super.onDrawerOpened(drawerView);
157 | if (!isAdded()) {
158 | return;
159 | }
160 |
161 | if (!mUserLearnedDrawer) {
162 | // The user manually opened the drawer; store this flag to prevent auto-showing
163 | // the navigation drawer automatically in the future.
164 | mUserLearnedDrawer = true;
165 | SharedPreferences sp = PreferenceManager
166 | .getDefaultSharedPreferences(getActivity());
167 | sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
168 | }
169 |
170 | getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
171 | }
172 | };
173 |
174 | // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
175 | // per the navigation drawer design guidelines.
176 | if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
177 | mDrawerLayout.openDrawer(mFragmentContainerView);
178 | }
179 |
180 | // Defer code dependent on restoration of previous instance state.
181 | mDrawerLayout.post(new Runnable() {
182 | @Override
183 | public void run() {
184 | mDrawerToggle.syncState();
185 | }
186 | });
187 |
188 | mDrawerLayout.setDrawerListener(mDrawerToggle);
189 | }
190 |
191 | private void selectItem(int position) {
192 | mCurrentSelectedPosition = position;
193 | if (mDrawerListView != null) {
194 | mDrawerListView.setItemChecked(position, true);
195 | }
196 | if (mDrawerLayout != null) {
197 | mDrawerLayout.closeDrawer(mFragmentContainerView);
198 | }
199 | if (mCallbacks != null) {
200 | mCallbacks.onNavigationDrawerItemSelected(position);
201 | }
202 | }
203 |
204 | @Override
205 | public void onAttach(Activity activity) {
206 | super.onAttach(activity);
207 | try {
208 | mCallbacks = (NavigationDrawerCallbacks) activity;
209 | } catch (ClassCastException e) {
210 | throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
211 | }
212 | }
213 |
214 | @Override
215 | public void onDetach() {
216 | super.onDetach();
217 | mCallbacks = null;
218 | }
219 |
220 | @Override
221 | public void onSaveInstanceState(Bundle outState) {
222 | super.onSaveInstanceState(outState);
223 | outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
224 | }
225 |
226 | @Override
227 | public void onConfigurationChanged(Configuration newConfig) {
228 | super.onConfigurationChanged(newConfig);
229 | // Forward the new configuration the drawer toggle component.
230 | mDrawerToggle.onConfigurationChanged(newConfig);
231 | }
232 |
233 | @Override
234 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
235 | // If the drawer is open, show the global app actions in the action bar. See also
236 | // showGlobalContextActionBar, which controls the top-left area of the action bar.
237 | if (mDrawerLayout != null && isDrawerOpen()) {
238 | inflater.inflate(R.menu.global, menu);
239 | showGlobalContextActionBar();
240 | }
241 | super.onCreateOptionsMenu(menu, inflater);
242 | }
243 |
244 | @Override
245 | public boolean onOptionsItemSelected(MenuItem item) {
246 | if (mDrawerToggle.onOptionsItemSelected(item)) {
247 | return true;
248 | }
249 |
250 | if (item.getItemId() == R.id.action_example) {
251 | Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show();
252 | return true;
253 | }
254 |
255 | return super.onOptionsItemSelected(item);
256 | }
257 |
258 | /**
259 | * Per the navigation drawer design guidelines, updates the action bar to show the global app
260 | * 'context', rather than just what's in the current screen.
261 | */
262 | private void showGlobalContextActionBar() {
263 | ActionBar actionBar = getActionBar();
264 | actionBar.setDisplayShowTitleEnabled(true);
265 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
266 | actionBar.setTitle(R.string.app_name);
267 | }
268 |
269 | private ActionBar getActionBar() {
270 | return getActivity().getActionBar();
271 | }
272 |
273 | /**
274 | * Callbacks interface that all activities using this fragment must implement.
275 | */
276 | public static interface NavigationDrawerCallbacks {
277 | /**
278 | * Called when an item in the navigation drawer is selected.
279 | */
280 | void onNavigationDrawerItemSelected(int position);
281 | }
282 | }
283 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/java/com/trey/marvel/dummy/DummyContent.java:
--------------------------------------------------------------------------------
1 | package com.trey.marvel.dummy;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * Helper class for providing sample content for user interfaces created by
10 | * Android template wizards.
11 | *
12 | * TODO: Replace all uses of this class before publishing your app.
13 | */
14 | public class DummyContent {
15 |
16 | /**
17 | * An array of sample (dummy) items.
18 | */
19 | public static List ITEMS = new ArrayList();
20 |
21 | /**
22 | * A map of sample (dummy) items, by ID.
23 | */
24 | public static Map ITEM_MAP = new HashMap();
25 |
26 | static {
27 | // Add 3 sample items.
28 | addItem(new DummyItem("1", "Item 1"));
29 | addItem(new DummyItem("2", "Item 2"));
30 | addItem(new DummyItem("3", "Item 3"));
31 | }
32 |
33 | private static void addItem(DummyItem item) {
34 | ITEMS.add(item);
35 | ITEM_MAP.put(item.id, item);
36 | }
37 |
38 | /**
39 | * A dummy item representing a piece of content.
40 | */
41 | public static class DummyItem {
42 | public String id;
43 | public String content;
44 |
45 | public DummyItem(String id, String content) {
46 | this.id = id;
47 | this.content = content;
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return content;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/java/com/trey/marvel/fragment/CharacterListFragment.java:
--------------------------------------------------------------------------------
1 | package com.trey.marvel.fragment;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.AbsListView;
10 | import android.widget.AdapterView;
11 | import android.widget.ArrayAdapter;
12 | import android.widget.ListAdapter;
13 | import android.widget.TextView;
14 |
15 | import com.trey.marvel.R;
16 | import com.trey.marvel.dummy.DummyContent;
17 |
18 | /**
19 | * A fragment representing a list of Items.
20 | *
21 | * Large screen devices (such as tablets) are supported by replacing the ListView
22 | * with a GridView.
23 | *
24 | * Activities containing this fragment MUST implement the {@link Callbacks}
25 | * interface.
26 | */
27 | public class CharacterListFragment extends Fragment implements AbsListView.OnItemClickListener {
28 |
29 | // TODO: Rename parameter arguments, choose names that match
30 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
31 | private static final String ARG_PARAM1 = "param1";
32 | private static final String ARG_PARAM2 = "param2";
33 |
34 | // TODO: Rename and change types of parameters
35 | private String mParam1;
36 | private String mParam2;
37 |
38 | private OnFragmentInteractionListener mListener;
39 |
40 | /**
41 | * The fragment's ListView/GridView.
42 | */
43 | private AbsListView mListView;
44 |
45 | /**
46 | * The Adapter which will be used to populate the ListView/GridView with
47 | * Views.
48 | */
49 | private ListAdapter mAdapter;
50 |
51 | // TODO: Rename and change types of parameters
52 | public static CharacterListFragment newInstance(String param1, String param2) {
53 | CharacterListFragment fragment = new CharacterListFragment();
54 | Bundle args = new Bundle();
55 | args.putString(ARG_PARAM1, param1);
56 | args.putString(ARG_PARAM2, param2);
57 | fragment.setArguments(args);
58 | return fragment;
59 | }
60 |
61 | /**
62 | * Mandatory empty constructor for the fragment manager to instantiate the
63 | * fragment (e.g. upon screen orientation changes).
64 | */
65 | public CharacterListFragment() {
66 | }
67 |
68 | @Override
69 | public void onCreate(Bundle savedInstanceState) {
70 | super.onCreate(savedInstanceState);
71 |
72 | if (getArguments() != null) {
73 | mParam1 = getArguments().getString(ARG_PARAM1);
74 | mParam2 = getArguments().getString(ARG_PARAM2);
75 | }
76 |
77 | // TODO: Change Adapter to display your content
78 | mAdapter = new ArrayAdapter(getActivity(),
79 | android.R.layout.simple_list_item_1, android.R.id.text1, DummyContent.ITEMS);
80 | }
81 |
82 | @Override
83 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
84 | Bundle savedInstanceState) {
85 | View view = inflater.inflate(R.layout.fragment_characterlistfragment, container, false);
86 |
87 | // Set the adapter
88 | mListView = (AbsListView) view.findViewById(android.R.id.list);
89 | ((AdapterView) mListView).setAdapter(mAdapter);
90 |
91 | // Set OnItemClickListener so we can be notified on item clicks
92 | mListView.setOnItemClickListener(this);
93 |
94 | return view;
95 | }
96 |
97 | @Override
98 | public void onAttach(Activity activity) {
99 | super.onAttach(activity);
100 | try {
101 | mListener = (OnFragmentInteractionListener) activity;
102 | } catch (ClassCastException e) {
103 | throw new ClassCastException(activity.toString()
104 | + " must implement OnFragmentInteractionListener");
105 | }
106 | }
107 |
108 | @Override
109 | public void onDetach() {
110 | super.onDetach();
111 | mListener = null;
112 | }
113 |
114 |
115 | @Override
116 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
117 | if (null != mListener) {
118 | // Notify the active callbacks interface (the activity, if the
119 | // fragment is attached to one) that an item has been selected.
120 | mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id);
121 | }
122 | }
123 |
124 | /**
125 | * The default content for this Fragment has a TextView that is shown when
126 | * the list is empty. If you would like to change the text, call this method
127 | * to supply the text it should use.
128 | */
129 | public void setEmptyText(CharSequence emptyText) {
130 | View emptyView = mListView.getEmptyView();
131 |
132 | if (emptyText instanceof TextView) {
133 | ((TextView) emptyView).setText(emptyText);
134 | }
135 | }
136 |
137 | /**
138 | * This interface must be implemented by activities that contain this
139 | * fragment to allow an interaction in this fragment to be communicated
140 | * to the activity and potentially other fragments contained in that
141 | * activity.
142 | *
143 | * See the Android Training lesson Communicating with Other Fragments for more information.
146 | */
147 | public interface OnFragmentInteractionListener {
148 | // TODO: Update argument type and name
149 | public void onFragmentInteraction(String id);
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-hdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-hdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-hdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-hdpi/ic_drawer.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-mdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-mdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-mdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-mdpi/ic_drawer.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-xhdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-xhdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-xhdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-xhdpi/ic_drawer.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-xxhdpi/drawer_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-xxhdpi/drawer_shadow.9.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-xxhdpi/ic_drawer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-xxhdpi/ic_drawer.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rdrobinson3/AndroidMarvelAPI/17f068736ee8f04c0673e7f52c32aa3441b2dc8b/marvel-demo/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
12 |
16 |
17 |
22 |
24 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/layout/fragment_characterlistfragment_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/layout/fragment_characterlistfragment_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/layout/fragment_navigation_drawer.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/layout/generic_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/menu/global.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/values-large/refs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 | - @layout/fragment_characterlistfragment_grid
11 |
12 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/values-sw600dp/refs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 | - @layout/fragment_characterlistfragment_grid
11 |
12 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
8 | 240dp
9 |
10 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/values/refs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 | - @layout/fragment_characterlistfragment_list
11 |
12 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Marvel
5 | Section 1
6 | Section 2
7 | Section 3
8 | Open navigation drawer
9 | Close navigation drawer
10 | Example action
11 | Settings
12 |
13 |
14 |
--------------------------------------------------------------------------------
/marvel-demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':marvel-demo'
2 | include 'marvel-api'
3 |
--------------------------------------------------------------------------------