Android Open Source - ExpandableListDemoApp My Activity






From Project

Back to project page ExpandableListDemoApp.

License

The source code is released under:

MIT License

If you think the Android project ExpandableListDemoApp 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 de.frost.david.android;
/*from  ww  w . j  a  v a 2 s .  c  om*/
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;

import de.frost.david.android.fragments.ItemListFragmentFragment;
import de.frost.david.android.fragments.NavigationDrawerFragment;


public class MyActivity extends Activity
        implements NavigationDrawerFragment.NavigationDrawerCallbacks, ItemListFragmentFragment.OnFragmentInteractionListener {

    private NavigationDrawerFragment mNavigationDrawerFragment;
    private CharSequence mTitle;

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

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

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

        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.container, PlaceholderFragment.newInstance())
                .commit();
    }

    @Override
    public void showList(String name, String[] items) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.container, ItemListFragmentFragment.newInstance(name, items))
                .commit();
    }

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (!mNavigationDrawerFragment.isDrawerOpen()) {
            restoreActionBar();
            return true;
        }
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public void setTitle(String name) {
        mTitle = name;
        getActionBar().setTitle(mTitle);
    }

    public static class PlaceholderFragment extends Fragment {
        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_my, container, false);
            return rootView;
        }

        @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);
            ((ItemListFragmentFragment.OnFragmentInteractionListener) activity).setTitle("Demo");
        }
    }

}




Java Source Code List

de.frost.david.android.ApplicationTest.java
de.frost.david.android.MyActivity.java
de.frost.david.android.adapters.DrawerExpandableAdapter.java
de.frost.david.android.fragments.ItemListFragmentFragment.java
de.frost.david.android.fragments.NavigationDrawerFragment.java
de.frost.david.android.model.Category.java
de.frost.david.android.model.SubCategory.java