package com.special.ResideMenuDemo;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.MotionEvent;
import android.view.View;
import com.special.ResideMenu.ResideMenu;
import com.special.ResideMenu.ResideMenuItem;

public class MenuActivity extends FragmentActivity implements View.OnClickListener{

    private ResideMenu resideMenu;
    private MenuActivity mContext;
    private FragmentTransaction fragmentTransaction;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mContext = this;
        fragmentTransaction = getSupportFragmentManager().beginTransaction();
        setUpMenu();
        changeFragment(new HomeFragment());
    }

    private void setUpMenu() {

        // attach to current activity;
        resideMenu = new ResideMenu(this);
        resideMenu.setBackground(R.drawable.menu_background);
        resideMenu.attachToActivity(this);

        // create menu items;
        String titles[] = { "Home", "Profile", "Calendar", "Settings" };
        int icon[] = { R.drawable.icon_home, R.drawable.icon_profile, R.drawable.icon_calendar, R.drawable.icon_settings };

        for (int i = 0; i < titles.length; i++){
            ResideMenuItem item = new ResideMenuItem(this, icon[i], titles[i]);
            item.setOnClickListener(this);
            resideMenu.addMenuItem(item);
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return resideMenu.onInterceptTouchEvent(ev) || super.dispatchTouchEvent(ev);
    }


    @Override
    public void onClick(View view) {
        resideMenu.closeMenu();
    }

    private void changeFragment(Fragment targetFragment){
        fragmentTransaction.replace(R.id.main_fragment, targetFragment);
        fragmentTransaction.commit();
    }

    // What good method is to access resideMenu？
    public ResideMenu getResideMenu(){
        return resideMenu;
    }
}

@@ -254,16 +254,45 @@
 w.View;%0A
+import android.widget.Toast;%0A
 import c
@@ -325,16 +325,16 @@
 deMenu;%0A
-
 import c
@@ -1191,16 +1191,66 @@
 y(this);
+%0A        resideMenu.setMenuListener(menuListener);
 %0A%0A      
@@ -1944,31 +1944,418 @@
 loseMenu();%0A
-
     %7D%0A%0A
+    private ResideMenu.OnMenuListener menuListener = new ResideMenu.OnMenuListener() %7B%0A        @Override%0A        public void openMenu() %7B%0A            Toast.makeText(mContext, %22Menu is opened!%22, Toast.LENGTH_SHORT).show();%0A        %7D%0A%0A        @Override%0A        public void closeMenu() %7B%0A            Toast.makeText(mContext, %22Menu is closed!%22, Toast.LENGTH_SHORT).show();%0A        %7D%0A    %7D;%0A%0A
     private 

add menu listener