Android Open Source - Android-Pulley-Menu Pulley Menu






From Project

Back to project page Android-Pulley-Menu.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCT...

If you think the Android project Android-Pulley-Menu 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 anshul.pulleymenu;
/* w w  w  . j a  v  a  2 s.  c  o  m*/
import anshul.pulleymenu.MenuDrawer.OnDrawerStateChangeListener;
import anshul.pulleymenu.MenuDrawer.Type;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.widget.ListView;

public class PulleyMenu {
  private Context context;
  private ListView menuview;
  int listsize;
  MenuDrawer mMenuDrawer;
  int localpx;
  int index;
  /**
   * Calls the Pulley Menu.
   * 
   * This Method also calls the SetContentView so no need to call it again 
   * 
   * 
   * @param  Activity      The Activity to attach with
   * @param  Contentview   Id of the Content View
   * @param  menuview      ListView of the menu
   * @param  Color1        The Color When a Option is Highlighted
   * @param  Color2        The normal Backgroud Color
   */
  public PulleyMenu(Activity activity, int Contentview,
      final ListView menuview, final int color1, final int color2) {
    context = activity;
    this.menuview = menuview;

    mMenuDrawer = MenuDrawer.attach(activity, Type.BEHIND, Position.TOP,
        MenuDrawer.MENU_DRAG_CONTENT);
    mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
    mMenuDrawer.setContentView(Contentview);
    menuview.setVerticalScrollBarEnabled(false);
    menuview.setHorizontalScrollBarEnabled(false);
    menuview.setDividerHeight(0);
  //  menuview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listsize = menuview.getAdapter().getCount();
    mMenuDrawer.setMenuView(menuview);

    // TODO Auto-generated constructor stub
    int size = (int) (listsize * 40 * context.getResources()
        .getDisplayMetrics().density);
size+=30;
    mMenuDrawer.setMenuSize(size);
    mMenuDrawer
        .setOnDrawerStateChangeListener(new OnDrawerStateChangeListener() {

          @Override
          public void onDrawerStateChange(int oldState, int newState) {
            // TODO Auto-generated method stub
            int globalpx = localpx;
            Log.d(oldState + "oldstate","old");
            Log.d(newState + "newstate","new");
            
            Log.d("Local called" + localpx, "Localpx");
            Log.d("index" + index,"index");
            if(oldState == MenuDrawer.STATE_OPEN && newState == MenuDrawer.STATE_CLOSING){
              
            }else{
            
            if (oldState == 2 && oldState != 8
                && newState == 8 || newState ==1 ) {

              Log.d("Local ps" + localpx, "Localpx");
              Log.d("globalpx" + globalpx,"globalpx");
              int offdp = (int) (globalpx / context.getResources()
                  .getDisplayMetrics().density);
              index = (int) offdp / 40;
              index--;
              menuview.clearAnimation();
              index = listsize - index;
              if (index >= 0 && index < listsize + 1) {
                Log.d("Clicked", "itemclicked");
                menuview.performItemClick(menuview, index,
                    menuview.getId());
              }
            }
            if (newState == MenuDrawer.STATE_OPENING
                || newState == MenuDrawer.STATE_OPEN) {
              mMenuDrawer.closeMenu();
              
            }
          }
          }
          @Override
          public void onDrawerSlide(float openRatio, int offsetPixels) {
            // TODO Auto-generated method stub
            localpx = offsetPixels;
            int offdp = (int) (localpx / context.getResources()
                .getDisplayMetrics().density);
            index = (int) offdp / 40;

            index = listsize - index;

            if (index >= 0) {

              for (int i = 0; i < listsize; i++) {
                if (i != index) {
                  menuview.getChildAt(i).setBackgroundColor(
                      color1);
                } else {
                  menuview.getChildAt(index)
                      .setBackgroundColor(color2);

                }
              }

            }
          }
        });

  }

}




Java Source Code List

anshul.pulleymenu.BuildLayerFrameLayout.java
anshul.pulleymenu.ColorDrawable.java
anshul.pulleymenu.CustomListViewAdapter.java
anshul.pulleymenu.DraggableDrawer.java
anshul.pulleymenu.FloatScroller.java
anshul.pulleymenu.MenuDrawer.java
anshul.pulleymenu.NoClickThroughFrameLayout.java
anshul.pulleymenu.OverlayDrawer.java
anshul.pulleymenu.PeekInterpolator.java
anshul.pulleymenu.Position.java
anshul.pulleymenu.PulleyMenu.java
anshul.pulleymenu.Scroller.java
anshul.pulleymenu.SinusoidalInterpolator.java
anshul.pulleymenu.SlideDrawable.java
anshul.pulleymenu.SlidingDrawer.java
anshul.pulleymenu.SmoothInterpolator.java
anshul.pulleymenu.StaticDrawer.java
anshul.pulleymenu.ViewHelper.java
anshul.pulleymenu.compat.ActionBarHelperNative.java
anshul.pulleymenu.compat.ActionBarHelperSherlock.java
anshul.pulleymenu.compat.ActionBarHelper.java
anshul.pulleymenu.samples.PulleyMenuSample.java
anshul.pulleymenu.test.java