/** 初始化View */
  private void initView() {
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    relativelayout = (RelativeLayout) findViewById(R.id.relativelayout);
    drawerArrow =
        new DrawerArrowDrawable(this) {
          @Override
          public boolean isLayoutRtl() {
            return false;
          }
        };
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, drawerArrow, R.string.drawer_open, R.string.drawer_close) {

          public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu();
          }

          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu();
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
  }
 @Override
 protected void onPostCreate(Bundle savedInstanceState) {
   super.onPostCreate(savedInstanceState);
   mDrawerToggle.syncState();
 }
 @Override
 public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   mDrawerToggle.onConfigurationChanged(newConfig);
 }
예제 #4
0
  @AfterViews
  void initDrawer() {
    ActionBar ab = getActionBar();
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setHomeButtonEnabled(true);
    drawerArrow =
        new DrawerArrowDrawable(this) {
          @Override
          public boolean isLayoutRtl() {
            return false;
          }
        };
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, drawerArrow, R.string.drawer_open, R.string.drawer_close) {

          public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu();
          }

          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu();
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

    String[] values = new String[] {"清除缓存", "停止后台服务"};
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_1, android.R.id.text1, values);
    mDrawerList.setAdapter(adapter);
    mDrawerList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
              case 0:
                Glide.get(getContext()).clearDiskCache();
                Glide.get(getContext()).clearMemory();
                mDrawerToggle.setAnimateEnabled(false);
                Toast.makeText(MainActivity.this, "缓存已清理", Toast.LENGTH_SHORT).show();
                break;
              case 1:
                stopService();
                Toast.makeText(MainActivity.this, "刷新服务已停止", Toast.LENGTH_SHORT).show();
                break;
              case 2:
                mDrawerToggle.setAnimateEnabled(true);
                mDrawerToggle.syncState();
                break;
              case 3:
                if (drawerArrowColor) {
                  drawerArrowColor = false;
                  drawerArrow.setColor(R.color.ldrawer_color);
                } else {
                  drawerArrowColor = true;
                  drawerArrow.setColor(R.color.drawer_arrow_second_color);
                }
                mDrawerToggle.syncState();
                break;
              case 4:
                Intent browserIntent =
                    new Intent(
                        Intent.ACTION_VIEW, Uri.parse("https://github.com/IkiMuhendis/LDrawer"));
                startActivity(browserIntent);
                break;
              case 5:
                Intent share = new Intent(Intent.ACTION_SEND);
                share.setType("text/plain");
                share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                share.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
                share.putExtra(
                    Intent.EXTRA_TEXT,
                    getString(R.string.app_description)
                        + "\n"
                        + "GitHub Page :  https://github.com/IkiMuhendis/LDrawer\n"
                        + "Sample App : https://play.google.com/store/apps/details?id="
                        + getPackageName());
                startActivity(Intent.createChooser(share, getString(R.string.app_name)));
                break;
              case 6:
                String appUrl = "https://play.google.com/store/apps/details?id=" + getPackageName();
                Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(appUrl));
                startActivity(rateIntent);
                break;
            }
          }
        });
    //        json();
    //

  }