Search in sources :

Example 1 with MainTabsFragment

use of com.amqtech.opensource.appintroexample.ui.fragment.MainTabsFragment in project AppIntro by apl-devs.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
    tb.setTitle(getResources().getString(R.string.app_name));
    tb.setTitleTextColor(Color.parseColor("#FFFFFF"));
    PrimaryDrawerItem item1 = new PrimaryDrawerItem().withIdentifier(1).withName("Home");
    PrimaryDrawerItem item2 = new PrimaryDrawerItem().withIdentifier(2).withName("Permissions");
    new DrawerBuilder().withActivity(this).withHeader(R.layout.util_drawer_hdr).withToolbar(tb).addDrawerItems(item1, item2).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem != null) {
                Fragment fragment = null;
                FragmentManager fragmentManager = getFragmentManager();
                switch((int) drawerItem.getIdentifier()) {
                    case 1:
                        fragment = new MainTabsFragment();
                        break;
                    case 2:
                        fragment = new PermissionTabsFragment();
                        break;
                }
                if (fragment != null) {
                    fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
                }
                if (drawerItem instanceof Nameable) {
                    setTitle(((Nameable) drawerItem).getName().getText(getApplicationContext()));
                }
            }
            return false;
        }
    }).withShowDrawerOnFirstLaunch(true).withFireOnInitialOnClick(true).withSavedInstance(savedInstanceState).build();
}
Also used : PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) Drawer(com.mikepenz.materialdrawer.Drawer) View(android.view.View) Fragment(android.app.Fragment) PermissionTabsFragment(com.amqtech.opensource.appintroexample.ui.fragment.PermissionTabsFragment) MainTabsFragment(com.amqtech.opensource.appintroexample.ui.fragment.MainTabsFragment) FragmentManager(android.app.FragmentManager) Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) MainTabsFragment(com.amqtech.opensource.appintroexample.ui.fragment.MainTabsFragment) PermissionTabsFragment(com.amqtech.opensource.appintroexample.ui.fragment.PermissionTabsFragment) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 MainTabsFragment (com.amqtech.opensource.appintroexample.ui.fragment.MainTabsFragment)1 PermissionTabsFragment (com.amqtech.opensource.appintroexample.ui.fragment.PermissionTabsFragment)1 Drawer (com.mikepenz.materialdrawer.Drawer)1 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)1 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)1 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)1 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)1