Android Open Source - BlurNavigationDrawer Main Activity






From Project

Back to project page BlurNavigationDrawer.

License

The source code is released under:

Apache License

If you think the Android project BlurNavigationDrawer 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

package com.charbgr.BlurNavigationDrawer.sample.app;
// ww w .jav  a  2  s  .  c o  m
import android.app.Activity;
import android.app.AlertDialog;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import java.util.ArrayList;


public class MainActivity extends ActionBarActivity {

    /**
     * Fragment managing the behaviors, interactions and presentation of the navigation drawer.
     */
    private NavigationDrawerFragment mNavigationDrawerFragment;

    /**
     * Used to store the last screen title. For use in {@link #restoreActionBar()}.
     */
    private CharSequence mTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //initialize container
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.container, PlaceholderFragment.newInstance())
                .commit();

        mNavigationDrawerFragment = (NavigationDrawerFragment)
                getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
        mTitle = getTitle();

        // Set up the drawer.
        mNavigationDrawerFragment.setUp(
                R.id.navigation_drawer,
                (DrawerLayout) findViewById(R.id.drawer_layout));
    }

    public void onSectionAttached(int number) {
        switch (number) {
            case 1:
                mTitle = getString(R.string.title_section1);
                break;
            case 2:
                mTitle = getString(R.string.title_section2);
                break;
            case 3:
                mTitle = getString(R.string.title_section3);
                break;
        }
    }

    public void restoreActionBar() {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(mTitle);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (!mNavigationDrawerFragment.isDrawerOpen()) {
            // Only show items in the action bar relevant to this screen
            // if the drawer is not showing. Otherwise, let the drawer
            // decide what to show in the action bar.
            getMenuInflater().inflate(R.menu.main, menu);
            restoreActionBar();
            return true;
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.about) {
            AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle(getString(R.string.app_name));
            alertDialog.setIcon(android.R.drawable.ic_dialog_info);
            alertDialog.setMessage("Developed by Basilis Charalampakis\n\n" +
                    "GitHub     : http://github.com/charbgr\n" +
                    "Linkedin  : http://linkedin.com/in/charalampakisbasilis/");
            alertDialog.show();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance() {
            PlaceholderFragment fragment = new PlaceholderFragment();
            return fragment;
        }

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {

            View rootView = inflater.inflate(R.layout.fragment_main, container, false);

            GridView gridView = (GridView) rootView.findViewById(R.id.gridview);

            Resources res = getActivity().getResources();

            ArrayList<Movie> movies = new ArrayList<Movie>();
            movies.add(new Movie(res.getDrawable(R.drawable.poster_about_time), "About Time"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_enders_game), "Enders Game"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_enough_said), "Enough Said"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_the_fifth_estate), "The fifth estate"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_gravity), "Gravity"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_cloudy_with_a_chance_of_meatballs_2), "Cloudy with a chance of meatballs"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_prisoners), "Prisoners"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_runner_runner), "Runner Runner"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_the_counselor), "The counselor"));
            movies.add(new Movie(res.getDrawable(R.drawable.poster_thor), "Thor"));


            gridView.setAdapter(new MovieAdapter(getActivity(), movies));

            return rootView;
        }
    }

}




Java Source Code List

com.charbgr.BlurNavigationDrawer.Blur.java
com.charbgr.BlurNavigationDrawer.sample.app.MainActivity.java
com.charbgr.BlurNavigationDrawer.sample.app.MovieAdapter.java
com.charbgr.BlurNavigationDrawer.sample.app.Movie.java
com.charbgr.BlurNavigationDrawer.sample.app.NavigationDrawerFragment.java
com.charbgr.BlurNavigationDrawer.v4.BlurActionBarDrawerToggle.java
com.charbgr.BlurNavigationDrawer.v4.BlurDrawerLayout.java
com.charbgr.BlurNavigationDrawer.v7.BlurActionBarDrawerToggle.java
com.charbgr.BlurNavigationDrawer.v7.BlurDrawerLayout.java