Exemple #1
0
 @Override
 public void onBackPressed() {
   if (result != null && result.isDrawerOpen()) {
     result.closeDrawer();
   } else {
     super.onBackPressed();
   }
 }
Exemple #2
0
 @Override
 public void onBackPressed() {
   if (menuDrawer != null && menuDrawer.isDrawerOpen()) {
     menuDrawer.closeDrawer();
   } else {
     super.onBackPressed();
   }
 }
Exemple #3
0
 @Override
 public void onBackPressed() {
   if (drawer.isDrawerOpen()) {
     drawer.closeDrawer();
   } else if (!curFrag.onBackPressed()) {
     if (fragmentManager.getBackStackEntryCount() == 0) drawer.openDrawer();
     else super.onBackPressed();
   }
 }
Exemple #4
0
 @Override
 public void onBackPressed() {
   // handle the back press :D close the drawer first and if the drawer is closed close the
   // activity
   if (result != null && result.isDrawerOpen()) {
     result.closeDrawer();
   } else {
     super.onBackPressed();
   }
 }
  @Override
  public boolean onItemClick(
      AdapterView<?> adapterView, View view, int position, long id, IDrawerItem item) {
    drawer.closeDrawer();
    if (item.getIdentifier() == visibleFragmentId) return false;

    switch (item.getIdentifier()) {
      case ID_FEEDBACK:
        String address = getString(R.string.feedback_mail_address);
        String subject = getString(R.string.feedback_mail_subject, getString(R.string.app_name));
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", address, null));
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        Intent mailer = Intent.createChooser(intent, getString(R.string.feedback_mail_chooser));
        startActivity(mailer);
        return false;

      case ID_OPEN_CHALLENGES:
        showFragment(new OpenChallengesFragment(), true);
        break;

      case ID_FINISHED_CHALLENGES:
        showFragment(new FinishedChallengesFragment(), true);
        break;

      case ID_SETTINGS:
        showFragment(new SettingsFragment(), true);
        break;

      default:
        return false;
    }

    visibleFragmentId = item.getIdentifier();
    return true;
  }
  @Override
  public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    ActionBar mActionBar = getSupportActionBar();

    int color = getResources().getColor(R.color.toolbar_green);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      // Overview color
      MainActivity.this.setTaskDescription(
          new ActivityManager.TaskDescription(
              "Linode",
              AndroidHelper.drawableToBitmap(getResources().getDrawable(R.mipmap.ic_launcher)),
              color));
    }

    if (mActionBar != null) {
      toolbar.setBackgroundColor(color);
      drawer
          .getDrawerLayout()
          .setStatusBarBackgroundColor(
              AndroidHelper.darkenColor(getResources().getColor(R.color.toolbar_green), 0.8f));

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(8);
      }
    }
  }
  @Override
  public void onBackPressed() {
    if (drawer != null && drawer.isDrawerOpen()) {
      drawer.closeDrawer();
    } else {
      if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) {
        super.onBackPressed();
        return;
      } else {
        Toast.makeText(getBaseContext(), R.string.press_back_again_toast, Toast.LENGTH_SHORT)
            .show();
      }

      mBackPressed = System.currentTimeMillis();
    }
  }
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   // add the values which need to be saved from the drawer to the bundle
   outState = result.saveInstanceState(outState);
   // add the values which need to be saved from the accountHeader to the bundle
   outState = headerResult.saveInstanceState(outState);
   super.onSaveInstanceState(outState);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_worker_availability);

    settings = PreferenceManager.getDefaultSharedPreferences(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    result =
        new DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .withSavedInstance(savedInstanceState)
            .build();
    result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            finish();
          }
        });
    data = (HashMap<Integer, String>) getIntent().getSerializableExtra("data");
    days = new ArrayList<>();
    mon = (CheckBox) findViewById(R.id.chkMon);
    tues = (CheckBox) findViewById(R.id.chkTues);
    wed = (CheckBox) findViewById(R.id.chkWed);
    thurs = (CheckBox) findViewById(R.id.chkThurs);
    fri = (CheckBox) findViewById(R.id.chkFri);
    sat = (CheckBox) findViewById(R.id.chkSat);
    sun = (CheckBox) findViewById(R.id.chkSun);
    days.add(mon);
    days.add(tues);
    days.add(wed);
    days.add(thurs);
    days.add(fri);
    days.add(sat);
    days.add(sun);

    availability = "\"availability\":[";

    try {
      action = getIntent().getAction();
      profileData = getIntent().getStringExtra("availability");
      jsonArray = new JSONArray(profileData);
      for (int i = 0; i < jsonArray.length(); i++) {
        days.get(jsonArray.getInt(i) - 1).setChecked(true);
      }
    } catch (Exception e) {
      action = "";
      profileData = "";
    }

    progress = new ProgressDialog(this);
    progress.setMessage("Updating profile");
  }
Exemple #10
0
  private void initDrawer() {
    drawer =
        new DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .withActionBarDrawerToggleAnimated(true)
            .withTranslucentStatusBar(false)
            .withHeader(R.layout.drawer_header)
            .withShowDrawerOnFirstLaunch(true)
            .addDrawerItems(
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_main_sec1_text)
                    .withIcon(FontAwesome.Icon.faw_graduation_cap),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_main_sec2_text)
                    .withIcon(FontAwesome.Icon.faw_university),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_main_sec3_text)
                    .withIcon(FontAwesome.Icon.faw_pencil),
                new DividerDrawerItem(),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_extra_sec1_text)
                    .withIcon(FontAwesome.Icon.faw_star)
                    .withSelectable(false))
            .addStickyDrawerItems(
                new SecondaryDrawerItem()
                    .withName(R.string.drawer_footer_sec1_text)
                    .withSelectable(false),
                new SecondaryDrawerItem()
                    .withName(R.string.drawer_footer_sec2_text)
                    .withSelectable(false))
            .withOnDrawerItemClickListener(
                new Drawer.OnDrawerItemClickListener() {
                  @Override
                  public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {

                    switch (position) {
                      case 1:
                        curFrag = new SearchFragment();
                        renderScreen();
                        break;
                      case 2:
                        curFrag = new CollegesFragment();
                        renderScreen();
                        break;
                      case 3:
                        curFrag = new OlympsFragment();
                        renderScreen();
                        break;
                      case 5:
                        curFrag = new SearchFragment(true);
                        renderScreen();
                        break;
                      default:
                        Toast.makeText(ctx, "Coming soon", Toast.LENGTH_SHORT).show();
                        return true;
                    }
                    drawer.closeDrawer();
                    return true;
                  }
                })
            .withOnDrawerListener(
                new Drawer.OnDrawerListener() {
                  @Override
                  public void onDrawerClosed(View view) {}

                  @Override
                  public void onDrawerOpened(View view) {}

                  @Override
                  public void onDrawerSlide(View view, float v) {}
                })
            .build();

    ActionBarDrawerToggle toggle = drawer.getActionBarDrawerToggle();

    ImageView headerImg = (ImageView) drawer.getHeader().findViewById(R.id.drawer_header_img);
    Picasso.with(this).load(R.drawable.face).into(headerImg);
  }
 public boolean isDrawerOpen() {
   return drawer.isDrawerOpen();
 }
  protected void initDrawer(Toolbar toolbar, final String className) {
    setSupportActionBar(toolbar);

    drawer =
        new DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .addDrawerItems(
                new PrimaryDrawerItem().withName(R.string.main_drawer_item),
                new PrimaryDrawerItem().withName(R.string.map_drawer_item))
            .withSelectedItem(-1)
            .build();
    drawer.setOnDrawerItemClickListener(
        new Drawer.OnDrawerItemClickListener() {
          @Override
          public boolean onItemClick(View view, int i, IDrawerItem iDrawerItem) {
            Intent intent;

            switch (i) {
              case 0:
                if (!className.equals("MainActivity")) {
                  intent = new Intent(DrawerBaseActivity.this, MainActivity.class);
                  startActivity(intent);

                  new Handler()
                      .postDelayed(
                          new Runnable() {
                            @Override
                            public void run() {
                              finish();
                            }
                          },
                          300);
                } else {
                  drawer.closeDrawer();
                  drawer.setSelection(-1);
                }
                break;
              case 1:
                if (!className.equals("MapActivity")) {
                  intent = new Intent(DrawerBaseActivity.this, MapActivity.class);
                  startActivity(intent);

                  new Handler()
                      .postDelayed(
                          new Runnable() {
                            @Override
                            public void run() {
                              finish();
                            }
                          },
                          300);
                } else {
                  drawer.closeDrawer();
                  drawer.setSelection(-1);
                }
                break;
              default:
            }
            return true;
          }
        });

    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    drawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);
  }
Exemple #13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_dark_toolbar);
    ButterKnife.bind(this);

    widget.addDecorators(
        new MySelectorDecorator(this), new HighlightWeekendsDecorator(), oneDayDecorator);

    new ApiSimulator().executeOnExecutor(Executors.newSingleThreadExecutor());

    // new ApiSimulator().executeOnExecutor(Executors.newSingleThreadExecutor());

    // Remove line to test RTL support
    // getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Create a few sample profile
    // NOTE you have to define the loader logic too. See the CustomApplication for more details
    final IProfile profile =
        new ProfileDrawerItem()
            .withName("Minny")
            .withEmail("*****@*****.**")
            .withIcon(
                "https://scontent.fbkk1-1.fna.fbcdn.net/hphotos-xal1/v/t1.0-9/6599_936554129769340_1064584668432410236_n.jpg?oh=ee89ac6349e1165aaf977c27d610d1aa&oe=57449387")
            .withIdentifier(100);
    final IProfile profile2 =
        new ProfileDrawerItem()
            .withName("Bernat Borras")
            .withEmail("*****@*****.**")
            .withIcon(Uri.parse("https://avatars3.githubusercontent.com/u/887462?v=3&s=460"))
            .withIdentifier(101);
    final IProfile profile3 =
        new ProfileDrawerItem()
            .withName("Max Muster")
            .withEmail("*****@*****.**")
            .withIcon(R.drawable.profile2)
            .withIdentifier(102);
    final IProfile profile4 =
        new ProfileDrawerItem()
            .withName("Felix House")
            .withEmail("*****@*****.**")
            .withIcon(R.drawable.profile3)
            .withIdentifier(103);
    final IProfile profile5 =
        new ProfileDrawerItem()
            .withName("Mr. X")
            .withEmail("*****@*****.**")
            .withIcon(R.drawable.profile4)
            .withIdentifier(104);
    final IProfile profile6 =
        new ProfileDrawerItem()
            .withName("Batman")
            .withEmail("*****@*****.**")
            .withIcon(R.drawable.profile5)
            .withIdentifier(105);

    // Create the AccountHeader
    headerResult =
        new AccountHeaderBuilder()
            .withActivity(this)
            .withHeaderBackground(R.drawable.header)
            .addProfiles(
                profile,
                /*profile2,
                profile3,
                profile4,
                profile5,
                profile6,*/
                // don't ask but google uses 14dp for the add account icon in gmail but 20dp for the
                // normal icons (like manage account)
                new ProfileSettingDrawerItem()
                    .withName("Add Account")
                    .withDescription("Add new GitHub Account")
                    .withIcon(
                        new IconicsDrawable(this, GoogleMaterial.Icon.gmd_plus)
                            .actionBar()
                            .paddingDp(5)
                            .colorRes(R.color.material_drawer_primary_text))
                    .withIdentifier(PROFILE_SETTING),
                new ProfileSettingDrawerItem()
                    .withName("Manage Account")
                    .withIcon(GoogleMaterial.Icon.gmd_settings))
            .withOnAccountHeaderListener(
                new AccountHeader.OnAccountHeaderListener() {
                  @Override
                  public boolean onProfileChanged(View view, IProfile profile, boolean current) {
                    // sample usage of the onProfileChanged listener
                    // if the clicked item has the identifier 1 add a new profile ;)
                    if (profile instanceof IDrawerItem
                        && ((IDrawerItem) profile).getIdentifier() == PROFILE_SETTING) {
                      int count = 100 + headerResult.getProfiles().size() + 1;
                      IProfile newProfile =
                          new ProfileDrawerItem()
                              .withNameShown(true)
                              .withName("Batman" + count)
                              .withEmail("batman" + count + "@gmail.com")
                              .withIcon(R.drawable.profile5)
                              .withIdentifier(count);
                      if (headerResult.getProfiles() != null) {
                        // we know that there are 2 setting elements. set the new profile above them
                        // ;)
                        headerResult.addProfile(newProfile, headerResult.getProfiles().size() - 2);
                      } else {
                        headerResult.addProfiles(newProfile);
                      }
                    }

                    // false if you have not consumed the event and it should close the drawer
                    return false;
                  }
                })
            .withSavedInstance(savedInstanceState)
            .build();

    // Create the drawer
    result =
        new DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .withHasStableIds(true)
            .withAccountHeader(
                headerResult) // set the AccountHeader we created earlier for the header
            .addDrawerItems(
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_profile_header)
                    .withDescription(R.string.drawer_item_profile_header_desc)
                    .withIcon(GoogleMaterial.Icon.gmd_face)
                    .withIdentifier(1)
                    .withSelectable(false),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_Menstr_header)
                    .withDescription(R.string.drawer_item_Menstr_header_desc)
                    .withIcon(GoogleMaterial.Icon.gmd_favorite)
                    .withIdentifier(2)
                    .withSelectable(false),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_Pregnant_header)
                    .withDescription(R.string.drawer_item_Pregnant_header_desc)
                    .withIcon(GoogleMaterial.Icon.gmd_alarm)
                    .withIdentifier(3)
                    .withSelectable(false),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_Contracation_header)
                    .withDescription(R.string.drawer_item_Contracation_header_desc)
                    .withIcon(GoogleMaterial.Icon.gmd_favorite_outline)
                    .withIdentifier(4)
                    .withSelectable(false)
                /*new PrimaryDrawerItem().withName(R.string.drawer_item_compact_header).withDescription(R.string.drawer_item_compact_header_desc).withIcon(GoogleMaterial.Icon.gmd_sun).withIdentifier(1).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_action_bar_drawer).withDescription(R.string.drawer_item_action_bar_drawer_desc).withIcon(FontAwesome.Icon.faw_home).withIdentifier(2).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_multi_drawer).withDescription(R.string.drawer_item_multi_drawer_desc).withIcon(FontAwesome.Icon.faw_gamepad).withIdentifier(3).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_non_translucent_status_drawer).withDescription(R.string.drawer_item_non_translucent_status_drawer_desc).withIcon(FontAwesome.Icon.faw_eye).withIdentifier(4).withSelectable(false).withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)),
                new PrimaryDrawerItem().withName(R.string.drawer_item_advanced_drawer).withDescription(R.string.drawer_item_advanced_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_adb).withIdentifier(5).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_keyboard_util_drawer).withDescription(R.string.drawer_item_keyboard_util_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_labels).withIdentifier(6).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_embedded_drawer).withDescription(R.string.drawer_item_embedded_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_battery).withIdentifier(7).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_fullscreen_drawer).withDescription(R.string.drawer_item_fullscreen_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_labels).withIdentifier(8).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_custom_container_drawer).withDescription(R.string.drawer_item_custom_container_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_my_location).withIdentifier(9).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_menu_drawer).withDescription(R.string.drawer_item_menu_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_filter_list).withIdentifier(10).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_mini_drawer).withDescription(R.string.drawer_item_mini_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_battery_charging).withIdentifier(11).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_fragment_drawer).withDescription(R.string.drawer_item_fragment_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_disc_full).withIdentifier(12).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_collapsing_toolbar_drawer).withDescription(R.string.drawer_item_collapsing_toolbar_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_camera_rear).withIdentifier(13).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_persistent_compact_header).withDescription(R.string.drawer_item_persistent_compact_header_desc).withIcon(GoogleMaterial.Icon.gmd_brightness_5).withIdentifier(14).withSelectable(false),
                new PrimaryDrawerItem().withName(R.string.drawer_item_crossfade_drawer_layout_drawer).withDescription(R.string.drawer_item_crossfade_drawer_layout_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_format_bold).withIdentifier(15).withSelectable(false),
                new SectionDrawerItem().withName(R.string.drawer_item_section_header),
                new SecondaryDrawerItem().withName("Collapsable").withIcon(GoogleMaterial.Icon.gmd_collection_case_play).withIdentifier(19).withSelectable(false),
                new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github).withIdentifier(20).withSelectable(false),
                new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(GoogleMaterial.Icon.gmd_format_color_fill).withIdentifier(21).withTag("Bullhorn"),
                new DividerDrawerItem(),
                new SwitchDrawerItem().withName("Switch").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener),
                new SwitchDrawerItem().withName("Switch2").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener).withSelectable(false),
                new ToggleDrawerItem().withName("Toggle").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener),
                new DividerDrawerItem(),
                new SecondarySwitchDrawerItem().withName("Secondary switch").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener),
                new SecondarySwitchDrawerItem().withName("Secondary Switch2").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener).withSelectable(false),
                new SecondaryToggleDrawerItem().withName("Secondary toggle").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener)*/
                ) // add the items we want to use with our Drawer
            .withOnDrawerItemClickListener(
                new Drawer.OnDrawerItemClickListener() {
                  @Override
                  public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    // check if the drawerItem is set.
                    // there are different reasons for the drawerItem to be null
                    // --> click on the header
                    // --> click on the footer
                    // those items don't contain a drawerItem

                    if (drawerItem != null) {
                      Intent intent = null;
                      if (drawerItem.getIdentifier() == 1) {
                        intent = new Intent(DrawerActivity.this, Profile.class);
                      } else if (drawerItem.getIdentifier() == 2) {
                        intent = new Intent(DrawerActivity.this, Menstruation.class);
                      } else if (drawerItem.getIdentifier() == 3) {
                        intent = new Intent(DrawerActivity.this, Pregnant.class);
                      } else if (drawerItem.getIdentifier() == 4) {
                        intent = new Intent(DrawerActivity.this, Contracaption.class);
                      } else if (drawerItem.getIdentifier() == 5) {
                        intent = new Intent(DrawerActivity.this, AdvancedActivity.class);
                      } else if (drawerItem.getIdentifier() == 6) {
                        intent = new Intent(DrawerActivity.this, KeyboardUtilActivity.class);
                      } else if (drawerItem.getIdentifier() == 7) {
                        intent = new Intent(DrawerActivity.this, EmbeddedDrawerActivity.class);
                      } else if (drawerItem.getIdentifier() == 8) {
                        intent = new Intent(DrawerActivity.this, FullscreenDrawerActivity.class);
                      } else if (drawerItem.getIdentifier() == 9) {
                        intent = new Intent(DrawerActivity.this, CustomContainerActivity.class);
                      } else if (drawerItem.getIdentifier() == 10) {
                        intent = new Intent(DrawerActivity.this, MenuDrawerActivity.class);
                      } else if (drawerItem.getIdentifier() == 11) {
                        intent = new Intent(DrawerActivity.this, MiniDrawerActivity.class);
                      } else if (drawerItem.getIdentifier() == 12) {
                        intent = new Intent(DrawerActivity.this, FragmentActivity.class);
                      } else if (drawerItem.getIdentifier() == 13) {
                        intent = new Intent(DrawerActivity.this, CollapsingToolbarActivity.class);
                      } else if (drawerItem.getIdentifier() == 14) {
                        intent = new Intent(DrawerActivity.this, PersistentDrawerActivity.class);
                      } else if (drawerItem.getIdentifier() == 15) {
                        intent =
                            new Intent(DrawerActivity.this, CrossfadeDrawerLayoutActvitiy.class);
                      } else if (drawerItem.getIdentifier() == 19) {
                        // showcase a simple collapsable functionality
                        if (opened) {
                          // remove the items which are hidden
                          result.removeItems(2000, 2001);
                        } else {
                          int curPos = result.getPosition(drawerItem);
                          result.addItemsAtPosition(
                              curPos,
                              new SecondaryDrawerItem()
                                  .withName("CollapsableItem")
                                  .withLevel(2)
                                  .withIcon(GoogleMaterial.Icon.gmd_8tracks)
                                  .withIdentifier(2000),
                              new SecondaryDrawerItem()
                                  .withName("CollapsableItem 2")
                                  .withLevel(2)
                                  .withIcon(GoogleMaterial.Icon.gmd_8tracks)
                                  .withIdentifier(2001));
                        }
                        opened = !opened;
                        return true;
                      } else if (drawerItem.getIdentifier() == 20) {
                        intent =
                            new LibsBuilder()
                                .withFields(R.string.class.getFields())
                                .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
                                .intent(DrawerActivity.this);
                      }
                      if (intent != null) {
                        DrawerActivity.this.startActivity(intent);
                      }
                    }

                    return false;
                  }
                })
            .withSavedInstance(savedInstanceState)
            .withShowDrawerOnFirstLaunch(true)
            .build();

    // if you have many different types of DrawerItems you can magically pre-cache those items to
    // get a better scroll performance
    // make sure to init the cache after the DrawerBuilder was created as this will first clear the
    // cache to make sure no old elements are in
    RecyclerViewCacheUtil.getInstance().withCacheSize(2).init(result);

    // only set the active selection or active profile if we do not recreate the activity
    if (savedInstanceState == null) {
      // set the selection to the item with the identifier 11
      result.setSelection(21, false);

      // set the active profile
      headerResult.setActiveProfile(profile);
    }

    result.updateBadge(4, new StringHolder(10 + ""));
  }
 public void closeDrawer() {
   drawer.closeDrawer();
 }
  public Drawer getMaterialDrawer() {
    AccountHeader headerResult =
        new AccountHeaderBuilder()
            .withActivity(activity)
            .withHeaderBackground(R.drawable.header_tourism)
            .withTranslucentStatusBar(false)
            .build();

    Drawer result =
        new DrawerBuilder()
            .withActivity(activity)
            .withToolbar(toolbar)
            .withTranslucentStatusBar(true)
            .withAccountHeader(headerResult)
            .addDrawerItems(
                new PrimaryDrawerItem()
                    .withName(R.string.navigation_item_map_name)
                    .withIcon(R.drawable.ic_map)
                    .withIdentifier(ITEM_MAP),
                new PrimaryDrawerItem()
                    .withName(R.string.navigation_item_search_name)
                    .withIcon(R.drawable.ic_magnify)
                    .withIdentifier(ITEM_SEARCH),
                new PrimaryDrawerItem()
                    .withName(R.string.navigation_item_marks_name)
                    .withIcon(R.drawable.ic_bookmark)
                    .withIdentifier(ITEM_MARKS),
                new DividerDrawerItem(),
                new PrimaryDrawerItem()
                    .withName(R.string.navigation_item_settings_name)
                    .withIcon(R.drawable.ic_settings)
                    .withIdentifier(ITEM_SETTINGS),
                new PrimaryDrawerItem()
                    .withName(R.string.navigation_item_help_name)
                    .withIcon(R.drawable.ic_help)
                    .withIdentifier(ITEM_HELP))
            .withOnDrawerItemClickListener(
                new Drawer.OnDrawerItemClickListener() {
                  @Override
                  public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    switch (drawerItem.getIdentifier()) {
                      case ITEM_SEARCH: // Поиск.
                        Intent search = new Intent(activity, SearchActivity.class);
                        search.putExtra(Constants.USER_ID, Constants.DEFAULT_USER_ID_VALUE);
                        activity.startActivityForResult(search, Constants.SHOW_SEARCH_ACTIVITY);
                        break;
                      case ITEM_MARKS: // Метки.
                        Intent marks = new Intent(activity, MarksActivity.class);
                        marks.putExtra(Constants.USER_ID, Constants.DEFAULT_USER_ID_VALUE);
                        marks.putExtra(MarksActivity.CALL_FILTER_OR_ADD_MARKS, false);
                        activity.startActivityForResult(marks, Constants.SHOW_MARKS_ACTIVITY);
                        break;
                      case ITEM_SETTINGS: // Настройки.
                        Intent settings = new Intent(activity, SettingsActivity.class);
                        activity.startActivityForResult(settings, Constants.SHOW_SETTINGS_ACTIVITY);
                        break;
                      case ITEM_HELP: // Помощь.
                        Intent help = new Intent(activity, HelpActivity.class);
                        activity.startActivityForResult(help, Constants.SHOW_HELP_ACTIVITY);
                        break;
                    }
                    return false;
                  }
                })
            .withSelectedItem(1)
            .build();

    // Анимация проворота иконки при клике на нее для вызова drawer-а.
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            activity,
            result.getDrawerLayout(),
            toolbar,
            R.string.navigation_view_open,
            R.string.navigation_view_close);
    result.getDrawerLayout().setDrawerListener(toggle);
    toggle.syncState();

    return result;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);

    // Handle Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Create a few sample profile
    final IProfile profile =
        new ProfileDrawerItem()
            .withName("Mike Penz")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile));
    final IProfile profile2 =
        new ProfileDrawerItem()
            .withName("Max Muster")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile2));
    final IProfile profile3 =
        new ProfileDrawerItem()
            .withName("Felix House")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile3));
    final IProfile profile4 =
        new ProfileDrawerItem()
            .withName("Mr. X")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile4));
    final IProfile profile5 =
        new ProfileDrawerItem()
            .withName("Batman")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile5));

    // Create the AccountHeader
    headerResult =
        new AccountHeaderBuilder()
            .withActivity(this)
            .withCompactStyle(true)
            .withHeaderBackground(R.drawable.header)
            .addProfiles(
                profile,
                profile2,
                profile3,
                profile4,
                profile5,
                // don't ask but google uses 14dp for the add account icon in gmail but 20dp for the
                // normal icons (like manage account)
                new ProfileSettingDrawerItem()
                    .withName("Add Account")
                    .withDescription("Add new GitHub Account")
                    .withIcon(
                        new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add)
                            .actionBarSize()
                            .paddingDp(5)
                            .colorRes(R.color.material_drawer_dark_primary_text))
                    .withIdentifier(PROFILE_SETTING),
                new ProfileSettingDrawerItem()
                    .withName("Manage Account")
                    .withIcon(GoogleMaterial.Icon.gmd_settings))
            .withSavedInstance(savedInstanceState)
            .build();

    // Create the drawer
    result =
        new DrawerBuilder()
            .withActivity(this)
            .withAccountHeader(
                headerResult) // set the AccountHeader we created earlier for the header
            .addDrawerItems(
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_home)
                    .withIcon(FontAwesome.Icon.faw_home)
                    .withIdentifier(1),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_free_play)
                    .withIcon(FontAwesome.Icon.faw_gamepad),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_custom)
                    .withIcon(FontAwesome.Icon.faw_eye),
                new SectionDrawerItem().withName(R.string.drawer_item_section_header),
                new SecondaryDrawerItem()
                    .withName(R.string.drawer_item_settings)
                    .withIcon(FontAwesome.Icon.faw_cog),
                new SecondaryDrawerItem()
                    .withName(R.string.drawer_item_help)
                    .withIcon(FontAwesome.Icon.faw_question)
                    .setEnabled(false),
                new SecondaryDrawerItem()
                    .withName(R.string.drawer_item_open_source)
                    .withIcon(FontAwesome.Icon.faw_github),
                new SecondaryDrawerItem()
                    .withName(R.string.drawer_item_contact)
                    .withIcon(FontAwesome.Icon.faw_bullhorn))
            .withOnDrawerItemClickListener(
                new Drawer.OnDrawerItemClickListener() {
                  @Override
                  public boolean onItemClick(
                      AdapterView<?> parent,
                      View view,
                      int position,
                      long id,
                      IDrawerItem drawerItem) {
                    if (drawerItem != null && drawerItem.getIdentifier() == 1) {
                      startSupportActionMode(new ActionBarCallBack());
                      findViewById(R.id.action_mode_bar)
                          .setBackgroundColor(
                              UIUtils.getThemeColorFromAttrOrRes(
                                  BRTDrawerActivity.this,
                                  R.attr.colorPrimary,
                                  R.color.material_drawer_primary));
                    }

                    if (drawerItem instanceof Nameable) {
                      toolbar.setTitle(((Nameable) drawerItem).getNameRes());
                    }

                    return false;
                  }
                })
            .withSavedInstance(savedInstanceState)
            .build();

    // set the selection to the item with the identifier 5
    result.setSelectionByIdentifier(5, false);

    // set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_embedded);

    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(R.string.drawer_item_embedded_drawer);

    // Create a few sample profile
    // NOTE you have to define the loader logic too. See the CustomApplication for more details
    final IProfile profile =
        new ProfileDrawerItem()
            .withName("Mike Penz")
            .withEmail("*****@*****.**")
            .withIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460");
    final IProfile profile2 =
        new ProfileDrawerItem()
            .withName("Bernat Borras")
            .withEmail("*****@*****.**")
            .withIcon(Uri.parse("https://avatars3.githubusercontent.com/u/887462?v=3&s=460"));
    final IProfile profile3 =
        new ProfileDrawerItem()
            .withName("Max Muster")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile2));
    final IProfile profile4 =
        new ProfileDrawerItem()
            .withName("Felix House")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile3));
    final IProfile profile5 =
        new ProfileDrawerItem()
            .withName("Mr. X")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile4))
            .withIdentifier(4);
    final IProfile profile6 =
        new ProfileDrawerItem()
            .withName("Batman")
            .withEmail("*****@*****.**")
            .withIcon(getResources().getDrawable(R.drawable.profile5));

    // Create the AccountHeader
    headerResult =
        new AccountHeaderBuilder()
            .withActivity(this)
            .withHeaderBackground(R.drawable.header)
            .withTranslucentStatusBar(false)
            .addProfiles(
                profile,
                profile2,
                profile3,
                profile4,
                profile5,
                profile6,
                // don't ask but google uses 14dp for the add account icon in gmail but 20dp for the
                // normal icons (like manage account)
                new ProfileSettingDrawerItem()
                    .withName("Add Account")
                    .withDescription("Add new GitHub Account")
                    .withIcon(GoogleMaterial.Icon.gmd_plus)
                    .withIdentifier(PROFILE_SETTING),
                new ProfileSettingDrawerItem()
                    .withName("Manage Account")
                    .withIcon(GoogleMaterial.Icon.gmd_settings))
            .withOnAccountHeaderListener(
                new AccountHeader.OnAccountHeaderListener() {
                  @Override
                  public boolean onProfileChanged(View view, IProfile profile, boolean current) {
                    // sample usage of the onProfileChanged listener
                    // if the clicked item has the identifier 1 add a new profile ;)
                    if (profile instanceof IDrawerItem
                        && ((IDrawerItem) profile).getIdentifier() == PROFILE_SETTING) {
                      IProfile newProfile =
                          new ProfileDrawerItem()
                              .withNameShown(true)
                              .withName("Batman")
                              .withEmail("*****@*****.**")
                              .withIcon(getResources().getDrawable(R.drawable.profile5));
                      if (headerResult.getProfiles() != null) {
                        // we know that there are 2 setting elements. set the new profile above them
                        // ;)
                        headerResult.addProfile(newProfile, headerResult.getProfiles().size() - 2);
                      } else {
                        headerResult.addProfiles(newProfile);
                      }
                    }

                    // false if you have not consumed the event and it should close the drawer
                    return false;
                  }
                })
            .withSavedInstance(savedInstanceState)
            .build();

    result =
        new DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .withTranslucentStatusBar(false)
            .withAccountHeader(
                headerResult) // set the AccountHeader we created earlier for the header
            .addDrawerItems(
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_compact_header)
                    .withIcon(GoogleMaterial.Icon.gmd_sun)
                    .withIdentifier(1),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_action_bar_drawer)
                    .withIcon(FontAwesome.Icon.faw_home)
                    .withBadge("22")
                    .withBadgeStyle(new BadgeStyle(Color.RED, Color.RED))
                    .withIdentifier(2),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_multi_drawer)
                    .withIcon(FontAwesome.Icon.faw_gamepad)
                    .withIdentifier(3),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_non_translucent_status_drawer)
                    .withIcon(FontAwesome.Icon.faw_eye)
                    .withIdentifier(4),
                new PrimaryDrawerItem()
                    .withDescription("A more complex sample")
                    .withName(R.string.drawer_item_advanced_drawer)
                    .withIcon(GoogleMaterial.Icon.gmd_adb)
                    .withIdentifier(5),
                new PrimaryDrawerItem()
                    .withName(R.string.drawer_item_keyboard_util_drawer)
                    .withIcon(GoogleMaterial.Icon.gmd_labels)
                    .withIdentifier(6),
                new SectionDrawerItem().withName(R.string.drawer_item_section_header),
                new SecondaryDrawerItem()
                    .withName(R.string.drawer_item_open_source)
                    .withIcon(FontAwesome.Icon.faw_github),
                new SecondaryDrawerItem()
                    .withName(R.string.drawer_item_contact)
                    .withIcon(GoogleMaterial.Icon.gmd_format_color_fill)
                    .withTag("Bullhorn"),
                new DividerDrawerItem(),
                new SwitchDrawerItem()
                    .withName("Switch")
                    .withIcon(Octicons.Icon.oct_tools)
                    .withChecked(true)
                    .withOnCheckedChangeListener(onCheckedChangeListener),
                new ToggleDrawerItem()
                    .withName("Toggle")
                    .withIcon(Octicons.Icon.oct_tools)
                    .withChecked(true)
                    .withOnCheckedChangeListener(
                        onCheckedChangeListener)) // add the items we want to use with our Drawer
            .withOnDrawerItemClickListener(
                new Drawer.OnDrawerItemClickListener() {
                  @Override
                  public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    if (drawerItem instanceof Nameable) {
                      Toast.makeText(
                              EmbeddedDrawerActivity.this,
                              ((Nameable) drawerItem)
                                  .getName()
                                  .getText(EmbeddedDrawerActivity.this),
                              Toast.LENGTH_SHORT)
                          .show();
                    }

                    return true;
                  }
                })
            .withSavedInstance(savedInstanceState)
            .buildView();

    ((ViewGroup) findViewById(R.id.frame_container)).addView(result.getSlider());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_main);

    //  Find the toolbar in XML
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    //  Set it's title text color to white
    toolbar.setTitleTextColor(Color.parseColor("#FFFFFF"));
    //  Change activity's action bar to toolbar
    setSupportActionBar(toolbar);

    LinodeApi.init(getBaseContext(), this);

    initImageLoader();

    accountHeader = buildHeader();

    //  Set up a new drawer builder
    drawer =
        new DrawerBuilder()
            .withActivity(this) //  Bind it to this activity
            .withToolbar(toolbar) //  Bind it to the toolbar attached to this activity
            .withAccountHeader(accountHeader)
            .withTranslucentNavigationBar(true) //  Disable translucent navigation menu/bar
            .addDrawerItems( //  Add our drawer items
                //  Regular drawer items
                new PrimaryDrawerItem()
                    .withIcon(R.drawable.server) //  Icon
                    .withSelectedIcon(R.drawable.server_tinted) //  Tinted icon
                    .withName(getResources().getString(R.string.item1)) //  Title
                    .withIdentifier(1) //  ID = 1
                    .withTextColor(Color.parseColor("#444444")) //  Text color
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)),
                new PrimaryDrawerItem()
                    .withIcon(R.drawable.sitemap)
                    .withSelectedIcon(R.drawable.sitemap_tinted) //  Tinted icon
                    .withName(getResources().getString(R.string.item2))
                    .withIdentifier(2) //  ID = 2
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)),
                new PrimaryDrawerItem()
                    .withIcon(R.drawable.dns)
                    .withSelectedIcon(R.drawable.dns_tinted) //  Tinted icon
                    .withName(getResources().getString(R.string.item3))
                    .withIdentifier(3) //  ID = 3
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)),
                new PrimaryDrawerItem()
                    .withIcon(R.drawable.library)
                    .withSelectedIcon(R.drawable.library_tinted) //  Tinted icon
                    .withName(getResources().getString(R.string.item4))
                    .withIdentifier(4) //  ID = 4
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green)),

                //  Divider
                new DividerDrawerItem(),

                //  Small/secondary drawer items
                new SecondaryDrawerItem()
                    .withIcon(R.drawable.account)
                    .withSelectedIcon(
                        R.drawable
                            .account_tinted) //  Tinted icon; not mandatory since this won't be
                                             // highlighted
                    .withName(getResources().getString(R.string.item5))
                    .withIdentifier(5) //  ID = 5
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green))
                    .withSelectable(false), //  Not a fragment; don't highlight
                new SecondaryDrawerItem()
                    .withIcon(R.drawable.information)
                    .withSelectedIcon(R.drawable.information_tinted)
                    .withName(getResources().getString(R.string.item6))
                    .withIdentifier(6) //  ID = 6
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green))
                    .withSelectable(false), //  Not a fragment; don't highlight
                new SecondaryDrawerItem()
                    .withIcon(R.drawable.logout)
                    .withSelectedIcon(R.drawable.logout_tinted)
                    .withName(getResources().getString(R.string.item7))
                    .withIdentifier(7) //  ID = 7
                    .withTextColor(Color.parseColor("#444444"))
                    .withSelectedTextColor(getResources().getColor(R.color.toolbar_green))
                    .withSelectable(false) //  Not a fragment; don't highlight
                )
            //  Attach onClickListeners for each drawer item (not dividers!)
            .withOnDrawerItemClickListener(
                new Drawer.OnDrawerItemClickListener() {

                  @Override
                  public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {

                    if (drawerItem != null) {
                      //   update the main content by replacing fragments
                      Fragment fragment = new LinodesFragment();
                      FragmentManager fragmentManager = getFragmentManager();

                      switch ((int) drawerItem.getIdentifier()) {
                        case 1:
                          fragment = new LinodesFragment();
                          break;
                        case 2:
                          fragment = new NodesFragment();
                          break;
                        case 3:
                          fragment = new DNSFragment();
                          break;
                        case 4:
                          fragment = new LibraryFragment();
                          break;
                        case 5:
                          // Account
                          Toast.makeText(getBaseContext(), "Demo Only", Toast.LENGTH_SHORT).show();
                          break;
                        case 6:
                          // About
                          Intent about = new Intent(MainActivity.this, AboutActivity.class);
                          startActivity(about);
                          break;
                        case 7:
                          // Log out
                          Toast.makeText(getBaseContext(), "Demo Only", Toast.LENGTH_SHORT).show();
                          break;
                      }
                      fragmentManager
                          .beginTransaction()
                          .replace(R.id.content_frame, fragment)
                          .commit();

                      if (drawerItem instanceof Nameable) {
                        setTitle(
                            ((Nameable) drawerItem).getName().getText(getApplicationContext()));
                      }
                    }

                    return false;
                  }
                })
            .withFireOnInitialOnClick(true)
            .withSavedInstance(savedInstanceState)
            .build();

    //  Set a custom shadow that overlays the main content when the drawer opens
    drawer.getDrawerLayout().setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    ActionBar mActionBar = getSupportActionBar();

    int color = getResources().getColor(R.color.toolbar_green);

    if (mActionBar != null) {
      toolbar.setBackgroundColor(color);
      drawer
          .getDrawerLayout()
          .setStatusBarBackgroundColor(
              AndroidHelper.darkenColor(getResources().getColor(R.color.toolbar_green), 0.8f));

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(8);
        getWindow()
            .setNavigationBarColor(
                AndroidHelper.darkenColor(getResources().getColor(R.color.toolbar_green), 0.8f));
      }
    }
  }