Esempio n. 1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_frame_content);
    setBehindContentView(R.layout.map_frame_left_menu);
    setSecondaryBehindContentView(R.layout.map_frame_right_menu);

    Button left = (Button) findViewById(R.id.map_left);
    left.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            toggle();
          }
        });

    Button right = (Button) findViewById(R.id.map_right);
    right.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            showSecondaryMenu();
          }
        });

    // mMapView = (MapView)findViewById(R.id.mapview);
    // if (mMapView == null) {
    //	return;
    // }
    // mMapView.addLayer(new
    // ArcGISTiledMapServiceLayer(getResources().getString(R.string.map_url)));

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    MapLeftMenuFragment leftMenuFragment = new MapLeftMenuFragment();
    MapRightMenuFragment rightMenuFragment = new MapRightMenuFragment();
    MapContentFragment mapFragment = new MapContentFragment();
    fragmentTransaction.replace(R.id.map_left_menu, leftMenuFragment);
    fragmentTransaction.replace(R.id.map_right_menu, rightMenuFragment);
    fragmentTransaction.replace(R.id.map_content, mapFragment);
    fragmentTransaction.commit();

    // customize the SlidingMenu
    SlidingMenu sm = getSlidingMenu();
    sm.setShadowWidth(50);
    sm.setShadowDrawable(R.drawable.shadow);
    sm.setBehindOffset(200);
    sm.setFadeDegree(0.35f);
    sm.setMode(SlidingMenu.LEFT_RIGHT);
    // 设置slding menu的几种手势模式
    // TOUCHMODE_FULLSCREEN 全屏模式,在content页面中,滑动,可以打开sliding menu
    // TOUCHMODE_MARGIN 边缘模式,在content页面中,如果想打开slding ,你需要在屏幕边缘滑动才可以打开slding menu
    // TOUCHMODE_NONE 自然是不能通过手势打开啦
    sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);

    // 使用左上方icon可点,这样在onOptionsItemSelected里面才可以监听到R.id.home
    // getActionBar().setDisplayHomeAsUpEnabled(true);
  }
  @Override
  protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    // configure the SlidingMenu
    SlidingMenu menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
    menu.setShadowWidth(15);
    menu.setBehindOffset(60);
    menu.setFadeDegree(0.35f);
    menu.setMenu(R.layout.sidemenu_frame);

    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.menu_frame, new SideMenu())
        .commit();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frame_content);
    setBehindContentView(R.layout.frame_menu);

    //	setSecondaryMenu

    SlidingMenu sm = getSlidingMenu();
    sm.setShadowWidth(50);
    sm.setShadowDrawable(R.drawable.shadow);
    sm.setBehindOffset(60);
    sm.setFadeDegree(0.35f);
    sm.setMode(SlidingMenu.LEFT_RIGHT);
    //  sm.set

    sm.setSecondaryMenu(R.layout.test1);
    sm.setSecondaryShadowDrawable(R.drawable.shadow);

    //    sm.setMenu(R.layout.frame_menu);
    // sm.setLeft(R.layout.frame_menu);
    // 设置slding menu的几种手势模式
    // TOUCHMODE_FULLSCREEN 全屏模式,在content页面中,滑动,可以打开sliding menu
    // TOUCHMODE_MARGIN 边缘模式,在content页面中,如果想打开slding ,你需要在屏幕边缘滑动才可以打开slding menu
    // TOUCHMODE_NONE 自然是不能通过手势打开啦
    sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

    //		FragmentTransaction fragmentTransaction=getFragmentManager().beginTransaction();
    //		MenuFragment menuFragment = new MenuFragment();
    //      //  fragmentTransaction.replace(R.id.menu, menuFragment);
    //        fragmentTransaction.replace(R.id.content, new ContentFragment("Welcome"),"Welcome");
    //        fragmentTransaction.commit();
    //
    //    //    getActionBar().setDisplayHomeAsUpEnabled(true);
  }
Esempio n. 4
0
 /**
  * Sets the shadow width.
  *
  * @param resId The dimension resource id to be set as the shadow width.
  */
 public void setShadowWidthRes(int resId) {
   setShadowWidth((int) getResources().getDimension(resId));
 }
Esempio n. 5
0
  /**
   * Instantiates a new SlidingMenu.
   *
   * @param context the associated Context
   * @param attrs the attrs
   * @param defStyle the def style
   */
  public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    LayoutParams behindParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mViewBehind = new CustomViewBehind(context);
    addView(mViewBehind, behindParams);
    LayoutParams aboveParams =
        new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mViewAbove = new CustomViewAbove(context);
    addView(mViewAbove, aboveParams);
    // register the CustomViewBehind with the CustomViewAbove
    mViewAbove.setCustomViewBehind(mViewBehind);
    mViewBehind.setCustomViewAbove(mViewAbove);
    mViewAbove.setOnPageChangeListener(
        new OnPageChangeListener() {
          public static final int POSITION_OPEN = 0;
          public static final int POSITION_CLOSE = 1;

          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          public void onPageSelected(int position) {
            if (position == POSITION_OPEN && mOpenListener != null) {
              mOpenListener.onOpen();
            } else if (position == POSITION_CLOSE && mCloseListener != null) {
              mCloseListener.onClose();
            }
          }
        });

    // now style everything!
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu);
    // set the above and behind views if defined in xml
    int mode = ta.getInt(R.styleable.SlidingMenu_mode, LEFT);
    setMode(mode);
    int viewAbove = ta.getResourceId(R.styleable.SlidingMenu_viewAbove, -1);
    if (viewAbove != -1) {
      setContent(viewAbove);
    } else {
      setContent(new FrameLayout(context));
    }
    int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1);
    if (viewBehind != -1) {
      setMenu(viewBehind);
    } else {
      setMenu(new FrameLayout(context));
    }
    int touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN);
    setTouchModeAbove(touchModeAbove);
    int touchModeBehind = ta.getInt(R.styleable.SlidingMenu_touchModeBehind, TOUCHMODE_MARGIN);
    setTouchModeBehind(touchModeBehind);

    int offsetBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindOffset, -1);
    int widthBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindWidth, -1);
    if (offsetBehind != -1 && widthBehind != -1)
      throw new IllegalStateException(
          "Cannot set both behindOffset and behindWidth for a SlidingMenu");
    else if (offsetBehind != -1) setBehindOffset(offsetBehind);
    else if (widthBehind != -1) setBehindWidth(widthBehind);
    else setBehindOffset(0);
    float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f);
    setBehindScrollScale(scrollOffsetBehind);
    int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1);
    if (shadowRes != -1) {
      setShadowDrawable(shadowRes);
    }
    int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0);
    setShadowWidth(shadowWidth);
    boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true);
    setFadeEnabled(fadeEnabled);
    float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0.33f);
    setFadeDegree(fadeDeg);
    boolean selectorEnabled = ta.getBoolean(R.styleable.SlidingMenu_selectorEnabled, false);
    setSelectorEnabled(selectorEnabled);
    int selectorRes = ta.getResourceId(R.styleable.SlidingMenu_selectorDrawable, -1);
    if (selectorRes != -1) setSelectorDrawable(selectorRes);
    ta.recycle();
  }