Back to project page ProjectStudio.
The source code is released under:
Apache License
If you think the Android project ProjectStudio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package fragments; /*from ww w . jav a 2s . co m*/ import android.app.ActionBar; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.PagerTabStrip; import android.support.v4.view.ViewPager; import android.support.v4.widget.DrawerLayout; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import com.example.uniutilproject.R; import java.lang.reflect.Field; import adapters.TasksTabPagerAdapter; /** * Created by desmond on 1/21/14. * */ public class TasksFragment extends Fragment { private DrawerLayout parent_drawer; private ViewPager viewpager; private ActionBar actionbar; private TasksTabPagerAdapter mAdapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tasks_fragment_view, container, false); //IF DRAWER HAS BEEN DISABLED BY SOME OTHER FRAGMENT //ENABLE DRAWER parent_drawer = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout); if (parent_drawer.getDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) == 0) { parent_drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); } //IN THIS CASE DRAWER HAS BEEN DISABLED TO PREVENT CONFLICT WITH SWIPE VIEW parent_drawer = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout); parent_drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); //CHANGE THE COLOR OF THE TAB STRIP PagerTabStrip pagerTabStrip = null; if (view != null) { pagerTabStrip = (PagerTabStrip) view.findViewById(R.id.tasks_pagerTabStrip); } assert pagerTabStrip != null; //pagerTabStrip.setDrawFullUnderline(true); pagerTabStrip.setTabIndicatorColorResource(R.color.actionbar_color); //INFLATE VIEWS HERE viewpager = (ViewPager) view.findViewById(R.id.tasks_view_pager); //INITIALIZATION //actionbar = getActivity().getActionBar(); mAdapter = new TasksTabPagerAdapter(getChildFragmentManager()); viewpager.setAdapter(mAdapter); return view; } @Override public void onDetach() { super.onDetach(); try { Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager"); childFragmentManager.setAccessible(true); childFragmentManager.set(this, null); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } // Register the fragment as a contributor to the Options Menu // call setHasOptions within its onCreate Handler @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } // add a menu item when this fragment is called @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); // custom menu (action bar layout) inflater.inflate(R.menu.task_menu, menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); // Find which menu item has been selected switch (item.getItemId()) { // Check for each known menu item case R.id.task_menu_addbtn: showChildFragment(); return true; // Return false if the menu item has not been handled default: return false; } } // private void showChildFragment() { FragmentManager fm = getFragmentManager(); AddTaskFragment frag = new AddTaskFragment(); FragmentTransaction transaction = fm.beginTransaction(); // For a little polish, specify a transition animation transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.replace(((ViewGroup) getView().getParent()).getId(), frag).addToBackStack(null).commit(); } //REMOVE THE THREE DOT ICON FROM THE ACTIONBAR, SINCE IT IS NOT NEEDED FOR NOW @Override public void onPrepareOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.action_settings); item.setVisible(false); super.onPrepareOptionsMenu(menu); } }