Search in sources :

Example 1 with MaterialHeadItemBackgroundOnClickListener

use of de.madcyph3r.materialnavigationdrawer.listener.MaterialHeadItemBackgroundOnClickListener in project AdvancedMaterialDrawer by madcyph3r.

the class HeadItemOneBackgroundOnClickListenerActivity 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 click on the background image from the head item.");
    Fragment fragmentInstruction = new FragmentInstruction();
    fragmentInstruction.setArguments(bundle);
    // create menu
    MaterialMenu menu = new MaterialMenu();
    menu.add(new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "Head Item Style (One Item), Background OnClick Listener"));
    menu.add(new MaterialItemSectionFragment(this, "Section 1", new FragmentDummy(), "Section 1"));
    menu.add(new MaterialItemSectionFragment(this, "Section 2", new FragmentDummy(), "Section 2"));
    menu.add(new MaterialItemSectionFragment(this, "Section 3", new FragmentDummy(), "Section 3"));
    // create Head Item
    // use bitmap and make a circle photo
    final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.head_item_icon);
    final RoundedCornersDrawable drawableAppIcon = new RoundedCornersDrawable(getResources(), bitmap);
    MaterialHeadItem headItem = new MaterialHeadItem(this, "My HeadItem", "My Subtitle", drawableAppIcon, R.drawable.mat1, menu);
    // set Avatar on click listener
    headItem.setBackgroundOnClickListener(new MaterialHeadItemBackgroundOnClickListener() {

        @Override
        public void onClick(MaterialHeadItem headItem) {
            Toast.makeText(drawer, "background on click", Toast.LENGTH_LONG).show();
        }
    });
    this.addHeadItem(headItem);
    // load menu
    this.loadMenu(getCurrentHeadItem().getMenu());
    // load the MaterialItemSectionFragment, from the given startIndex
    this.loadStartFragmentFromMenu(getCurrentHeadItem().getMenu());
}
Also used : Bitmap(android.graphics.Bitmap) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) Bundle(android.os.Bundle) RoundedCornersDrawable(de.madcyph3r.materialnavigationdrawer.tools.RoundedCornersDrawable) MaterialHeadItemBackgroundOnClickListener(de.madcyph3r.materialnavigationdrawer.listener.MaterialHeadItemBackgroundOnClickListener) MaterialMenu(de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu) MaterialHeadItem(de.madcyph3r.materialnavigationdrawer.head.MaterialHeadItem) FragmentDummy(de.madcyph3r.example.example.FragmentDummy) FragmentInstruction(de.madcyph3r.example.example.FragmentInstruction) Fragment(android.support.v4.app.Fragment) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)

Aggregations

Bitmap (android.graphics.Bitmap)1 Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 FragmentDummy (de.madcyph3r.example.example.FragmentDummy)1 FragmentInstruction (de.madcyph3r.example.example.FragmentInstruction)1 MaterialHeadItem (de.madcyph3r.materialnavigationdrawer.head.MaterialHeadItem)1 MaterialHeadItemBackgroundOnClickListener (de.madcyph3r.materialnavigationdrawer.listener.MaterialHeadItemBackgroundOnClickListener)1 MaterialMenu (de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu)1 MaterialItemSectionFragment (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)1 RoundedCornersDrawable (de.madcyph3r.materialnavigationdrawer.tools.RoundedCornersDrawable)1