Пример #1
0
 /** 侧滑菜单初始化 */
 public void initMenuview() {
   View settingview = getLayoutInflater().inflate(R.layout.main_setting, null);
   mDrawer.setMenuView(settingview);
   // menudrawer的侧滑界面的listview
   mListView = (ListView) settingview.findViewById(R.id.listView1);
   String[] mTitle = getResources().getStringArray(R.array.menu_str);
   int images[] =
       new int[] {
         R.drawable.ic_menu_login,
         R.drawable.ic_menu_home,
         R.drawable.ic_menu_group,
         R.drawable.ic_menu_public,
         R.drawable.ic_menu_setting
       };
   /** 用户登陆判断* */
   //		SharedPreferences sp = getPreferences(MODE_PRIVATE);
   SharedPreferences sp = getSharedPreferences("userinfo", 0);
   // 自动登陆
   autologin = sp.getBoolean("autologin", false);
   if (autologin) {
     username = sp.getString("username", "cpoopc");
   } else {
     sp.edit().putString("username", "").commit();
   }
   // 用户名
   if (username != null && !"".equals(username)) {
     mTitle[0] = username;
   }
   settingAdapter = new SettingAdapter(this, mTitle, images);
   mListView.setAdapter(settingAdapter);
   mListView.setOnItemClickListener(this);
   //		mDrawer.setDropShadowColor(Color.BLUE);
   mDrawer.setSlideDrawable(R.drawable.ic_setting);
   mDrawer.setDrawerIndicatorEnabled(true);
   mDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN);
   mDrawer.setMenuSize(250);
   // 第一次使用提示可以侧滑
   boolean firstUse = sp.getBoolean("firstUse", true);
   if (firstUse) {
     mDrawer.peekDrawer(1000, 0);
     Editor edit = sp.edit();
     edit.putBoolean("firstUse", false);
     edit.commit();
   }
 }
Пример #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(
        Window.FEATURE_INDETERMINATE_PROGRESS); // for progress it will be passed before layout

    // navigation
    if (savedInstanceState != null) {
      mActiveViewId = savedInstanceState.getInt(STATE_ACTIVE_VIEW_ID);
    }

    mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_WINDOW);
    mMenuDrawer.setMenuView(R.layout.menu_scrollview); // this is the layout for

    ////////////////////////////////////////////////////
    // Action bar
    ActionBar mActionBar;
    LayoutInflater mInflater;
    View mCustomView;
    TextView mTitleTextView;
    mActionBar = getSupportActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    mInflater = LayoutInflater.from(this);
    mCustomView = mInflater.inflate(R.layout.menu, null);
    mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
    mTitleTextView.setText("Live");
    mTitleTextView.setTextSize(20);

    mActionBar.setCustomView(mCustomView);
    mActionBar.setDisplayShowCustomEnabled(true);
    // mActionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.at_header_bg));
    ImageButton ibItem1 = (ImageButton) findViewById(R.id.btn_slide);
    ibItem1.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            mMenuDrawer.toggleMenu();
          }
        });

    /////////////////////////////////////////////

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      //           getActionBar().setDisplayHomeAsUpEnabled(true);
      // this is for the color of title bar
      ColorDrawable colorDrawable = new ColorDrawable();
      int myColor = this.getResources().getColor(R.color.menu4);
      colorDrawable.setColor(myColor);
      android.app.ActionBar actionBar = getActionBar();
      actionBar.setBackgroundDrawable(colorDrawable);
    }

    // mContentTextView = (TextView) findViewById(R.id.contentText);
    findViewById(R.id.item1).setOnClickListener(this);
    findViewById(R.id.item2).setOnClickListener(this);
    findViewById(R.id.item3).setOnClickListener(this);
    findViewById(R.id.item4).setOnClickListener(this);
    findViewById(R.id.item5).setOnClickListener(this);
    findViewById(R.id.item6).setOnClickListener(this);
    findViewById(R.id.item7).setOnClickListener(this);
    findViewById(R.id.item8).setOnClickListener(this);

    TextView activeView = (TextView) findViewById(mActiveViewId);
    if (activeView != null) {
      mMenuDrawer.setActiveView(activeView);
      // mContentTextView.setText("Active item: " + activeView.getText());
    }

    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    mMenuDrawer.setMenuSize(width / 4); // size of menu
    mMenuDrawer.setDropShadow(android.R.color.transparent); // removin showdo
    // navigation

    if (isNetworkOnline() == true) { // starting settings if internet is not working
      internt_count = true;
      iamcallin(); // calling the function to build everything

    } else if (isNetworkOnline() == false) {
      setContentView(R.layout.nointernet); // giving new layout to drawer
      // setContentView(R.layout.nointernet);
      internt_count = false;
      Button button = (Button) findViewById(R.id.nointernet_refresh);

      button.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View arg0) {

              Intent myIntent = new Intent(live_first.this, live_first.class); // refreshing

              startActivity(myIntent);
              finish();
            }
          });
    }
  }