Search in sources :

Example 46 with Fragment

use of android.support.v4.app.Fragment in project PocketHub by pockethub.

the class HomePagerAdapter method getItem.

@Override
public Fragment getItem(int position) {
    Fragment fragment = null;
    switch(position) {
        case 0:
            fragment = defaultUser ? new UserReceivedNewsFragment() : new OrganizationNewsFragment();
            break;
        case 1:
            fragment = new RepositoryListFragment();
            break;
        case 2:
            fragment = defaultUser ? new MyFollowersFragment() : new MembersFragment();
            break;
        case 3:
            fragment = new MyFollowingFragment();
            break;
    }
    if (fragment != null) {
        Bundle args = new Bundle();
        args.putParcelable("org", org);
        fragment.setArguments(args);
    }
    return fragment;
}
Also used : Bundle(android.os.Bundle) RepositoryListFragment(com.github.pockethub.android.ui.repo.RepositoryListFragment) Fragment(android.support.v4.app.Fragment) RepositoryListFragment(com.github.pockethub.android.ui.repo.RepositoryListFragment)

Example 47 with Fragment

use of android.support.v4.app.Fragment in project OkVolley by googolmo.

the class DrawerFragment method setUp.

/**
     * Users of this fragment must call this method to set up the navigation drawer interactions.
     *
     * @param fragmentId   The android:id of this fragment in its activity's layout.
     * @param drawerLayout The DrawerLayout containing this fragment's UI.
     */
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close) {

        /* "close drawer" description for accessibility */
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }
            // calls onPrepareOptionsMenu()
            getActivity().supportInvalidateOptionsMenu();
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }
            // calls onPrepareOptionsMenu()
            getActivity().supportInvalidateOptionsMenu();
        }
    };
    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(new Runnable() {

        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}
Also used : ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ActionBar(android.support.v7.app.ActionBar)

Example 48 with Fragment

use of android.support.v4.app.Fragment in project ListenerMusicPlayer by hefuyicoder.

the class NavigationUtil method navigateToPlaylistDetail.

@TargetApi(21)
public static void navigateToPlaylistDetail(Activity context, long playlistID, String playlistName, long firstAlbumID, Pair<View, String> transitionViews) {
    FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager().beginTransaction();
    Fragment fragment;
    if (isLollipop() && transitionViews != null) {
        Transition changeImage = TransitionInflater.from(context).inflateTransition(R.transition.image_transform);
        transaction.addSharedElement(transitionViews.first, transitionViews.second);
        fragment = PlaylistDetailFragment.newInstance(playlistID, playlistName, firstAlbumID, true, transitionViews.second);
        fragment.setSharedElementEnterTransition(changeImage);
        fragment.setSharedElementReturnTransition(changeImage);
    } else {
        transaction.setCustomAnimations(R.anim.activity_fade_in, R.anim.activity_fade_out, R.anim.activity_fade_in, R.anim.activity_fade_out);
        fragment = PlaylistDetailFragment.newInstance(playlistID, playlistName, firstAlbumID, false, transitionViews.second);
    }
    transaction.hide(((AppCompatActivity) context).getSupportFragmentManager().findFragmentById(R.id.fragment_container));
    transaction.add(R.id.fragment_container, fragment);
    transaction.addToBackStack(null).commit();
}
Also used : FragmentTransaction(android.support.v4.app.FragmentTransaction) Transition(android.transition.Transition) AppCompatActivity(android.support.v7.app.AppCompatActivity) PlaylistDetailFragment(io.hefuyi.listener.ui.fragment.PlaylistDetailFragment) ArtistDetailFragment(io.hefuyi.listener.ui.fragment.ArtistDetailFragment) Fragment(android.support.v4.app.Fragment) FolderSongsFragment(io.hefuyi.listener.ui.fragment.FolderSongsFragment) AlbumDetailFragment(io.hefuyi.listener.ui.fragment.AlbumDetailFragment) TargetApi(android.annotation.TargetApi)

Example 49 with Fragment

use of android.support.v4.app.Fragment in project StatusBarUtil by laobie.

the class UseInFragmentActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_use_in_fragment);
    mVpHome = (ViewPager) findViewById(R.id.vp_home);
    mBottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.ic_favorite, "One")).addItem(new BottomNavigationItem(R.drawable.ic_gavel, "Two")).addItem(new BottomNavigationItem(R.drawable.ic_grade, "Three")).addItem(new BottomNavigationItem(R.drawable.ic_group_work, "Four")).initialise();
    mBottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {

        @Override
        public void onTabSelected(int position) {
            mVpHome.setCurrentItem(position);
        }

        @Override
        public void onTabUnselected(int position) {
        }

        @Override
        public void onTabReselected(int position) {
        }
    });
    mFragmentList.add(new ImageFragment());
    mFragmentList.add(new SimpleFragment());
    mFragmentList.add(new SimpleFragment());
    mFragmentList.add(new SimpleFragment());
    mVpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            mBottomNavigationBar.selectTab(position);
            switch(position) {
                case 0:
                    break;
                default:
                    Random random = new Random();
                    int color = 0xff000000 | random.nextInt(0xffffff);
                    if (mFragmentList.get(position) instanceof SimpleFragment) {
                        ((SimpleFragment) mFragmentList.get(position)).setTvTitleBackgroundColor(color);
                    }
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    mVpHome.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment) BottomNavigationBar(com.ashokvarma.bottomnavigation.BottomNavigationBar) Random(java.util.Random) BottomNavigationItem(com.ashokvarma.bottomnavigation.BottomNavigationItem)

Example 50 with Fragment

use of android.support.v4.app.Fragment in project AdvancedMaterialDrawer by madcyph3r.

the class NoClosePrevDrawerActivity_Activity method init.

@Override
public void init(Bundle savedInstanceState) {
    drawer = this;
    // information text for the fragment
    Bundle bundle = new Bundle();
    bundle.putString("instruction", "Open the drawer and choose the 'start activity' section. Then press back, \" +\n" + "                \"you will get back to this activity.");
    Fragment fragmentInstruction = new FragmentInstruction();
    fragmentInstruction.setArguments(bundle);
    // create menu
    MaterialMenu menu = new MaterialMenu();
    menu.add(new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "No Close Previous Drawer Activity"));
    menu.add(new MaterialItemDevisor());
    menu.add(new MaterialItemSectionActivity(this, "start Activity", new Intent(this, NoCloseActivity.class)));
    // load menu
    this.loadMenu(menu);
    // load first MaterialItemSectionFragment in the menu, because there is no start position
    this.loadStartFragmentFromMenu(menu);
}
Also used : MaterialItemSectionActivity(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionActivity) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) Bundle(android.os.Bundle) MaterialItemDevisor(de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemDevisor) MaterialMenu(de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu) Intent(android.content.Intent) FragmentInstruction(de.madcyph3r.example.example.FragmentInstruction) Fragment(android.support.v4.app.Fragment) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)

Aggregations

Fragment (android.support.v4.app.Fragment)663 FragmentTransaction (android.support.v4.app.FragmentTransaction)233 Bundle (android.os.Bundle)149 View (android.view.View)140 FragmentManager (android.support.v4.app.FragmentManager)134 DialogFragment (android.support.v4.app.DialogFragment)80 TextView (android.widget.TextView)59 FragmentInstruction (de.madcyph3r.example.example.FragmentInstruction)48 MaterialMenu (de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu)48 MaterialItemSectionFragment (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)48 FragmentDummy (de.madcyph3r.example.example.FragmentDummy)43 Intent (android.content.Intent)41 ViewPager (android.support.v4.view.ViewPager)38 FragmentActivity (android.support.v4.app.FragmentActivity)34 ImageView (android.widget.ImageView)32 BaseFragment (com.waz.zclient.pages.BaseFragment)29 ArrayList (java.util.ArrayList)28 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)25 Button (android.widget.Button)24 ActionBar (android.support.v7.app.ActionBar)23