Android Open Source - rss Fragment Navigation Drawer






From Project

Back to project page rss.

License

The source code is released under:

GNU General Public License

If you think the Android project rss listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version./*from  w w  w . ja va  2 s.  c  om*/
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package com.poloure.simplerss;

import android.app.ActionBar;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.poloure.simplerss.adapters.AdapterNavigationDrawer;

import static com.poloure.simplerss.Constants.*;

public
class FragmentNavigationDrawer extends Fragment
{
    private static
    class OnNavigationItemClick implements AdapterView.OnItemClickListener
    {
        @Override
        public
        void onItemClick(AdapterView<?> parent, View view, int absolutePos, long id)
        {
            // Close the navigation drawer in all cases.
            s_drawerLayout.closeDrawers();

            // Decide which fragment to load for each header position.
            Fragment[] fragments = {
                    s_fragmentFavourites, s_fragmentManage, s_fragmentSettings, s_fragmentFeeds,
            };
            int position = fragments.length - 1 < absolutePos ? fragments.length - 1 : absolutePos;
            Utilities.setTitlesAndDrawerAndPage(fragments[position], absolutePos);
        }
    }

    private static
    class SyncPost implements Runnable
    {
        @Override
        public
        void run()
        {
            s_drawerToggle.syncState();
        }
    }

    private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
    ListView m_listView;
    private boolean m_userLearnedDrawer;

    @Override
    public
    void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // Read the application preferences to see if the user knows the drawer exists.
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
        m_userLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
    }

    @Override
    public
    View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        m_listView = (ListView) inflater.inflate(R.layout.navigation_drawer, container, false);
        m_listView.setOnItemClickListener(new OnNavigationItemClick());
        m_listView.setHeaderDividersEnabled(false);

        String[] navTitles = getResources().getStringArray(R.array.navigation_titles);

        for(int i = 0; i < navTitles.length; i++)
        {
            ViewNavItem item = new ViewNavItem(getActivity());
            item.m_text = navTitles[i];
            item.m_count = "";
            item.m_image = i;
            m_listView.addHeaderView(item);
        }

        TextView divider = (TextView) inflater.inflate(R.layout.navigation_divider, container, false);
        divider.setText(R.string.tags);

        m_listView.addHeaderView(divider, null, false);
        m_listView.setAdapter(new AdapterNavigationDrawer(getActivity()));

        return m_listView;
    }

    @Override
    public
    void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
        s_drawerToggle.onConfigurationChanged(newConfig);
    }

    void setUp(DrawerLayout drawerLayout)
    {
        final FeedsActivity activity = (FeedsActivity) getActivity();

        // Set up the action bar.
        ActionBar actionBar = activity.getActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        s_drawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close)
        {
            @Override
            public
            void onDrawerSlide(View drawerView, float slideOffset)
            {
                super.onDrawerSlide(drawerView, slideOffset);

                activity.m_showMenuItems = 0.0F == slideOffset;
                activity.invalidateOptionsMenu();
            }

            @Override
            public
            void onDrawerOpened(View drawerView)
            {
                super.onDrawerOpened(drawerView);

                if(!m_userLearnedDrawer)
                {
                    m_userLearnedDrawer = true;
                    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                    sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit();
                }
            }
        };

        // Open the drawer if the user has never opened it manually before.
        if(!m_userLearnedDrawer)
        {
            drawerLayout.openDrawer(Gravity.START);
        }

        drawerLayout.post(new SyncPost());
        drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        drawerLayout.setDrawerListener(s_drawerToggle);
    }
}




Java Source Code List

com.poloure.simplerss.AsyncCheckFeed.java
com.poloure.simplerss.AsyncLoadImage.java
com.poloure.simplerss.AsyncManageAdapter.java
com.poloure.simplerss.AsyncNavigationAdapter.java
com.poloure.simplerss.AsyncNewTagAdapters.java
com.poloure.simplerss.Constants.java
com.poloure.simplerss.DialogConfirm.java
com.poloure.simplerss.DialogEditFeed.java
com.poloure.simplerss.FeedItem.java
com.poloure.simplerss.FeedsActivity.java
com.poloure.simplerss.FragmentFeeds.java
com.poloure.simplerss.FragmentNavigationDrawer.java
com.poloure.simplerss.FragmentSettings.java
com.poloure.simplerss.IndexItem.java
com.poloure.simplerss.ListFragmentFavourites.java
com.poloure.simplerss.ListFragmentManage.java
com.poloure.simplerss.ListFragmentTag.java
com.poloure.simplerss.ObjectIO.java
com.poloure.simplerss.PagerAdapterTags.java
com.poloure.simplerss.RssLogger.java
com.poloure.simplerss.ServiceUpdate.java
com.poloure.simplerss.Utilities.java
com.poloure.simplerss.ViewFeedItem.java
com.poloure.simplerss.ViewNavItem.java
com.poloure.simplerss.ViewPagerDelegate.java
com.poloure.simplerss.adapters.AdapterFeedItems.java
com.poloure.simplerss.adapters.AdapterManageItems.java
com.poloure.simplerss.adapters.AdapterNavigationDrawer.java
com.poloure.simplerss.adapters.LinkedMapAdapter.java
com.poloure.simplerss.asynctasks.AsyncTaskSaveImage.java
com.poloure.simplerss.fragments.FragmentWebView.java
com.poloure.simplerss.listeners.MultiModeListenerFavourites.java
com.poloure.simplerss.listeners.MultiModeListenerManage.java
com.poloure.simplerss.listeners.MultiModeListener.java
com.poloure.simplerss.ui.ListViewFeeds.java