Exemplo n.º 1
0
  private void updateDrawer(boolean updateFavorites) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    assert navigationView != null : "Navigation view is null";

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
      navigationView.setItemIconTintList(null);

    MenuItem stats = navigationView.getMenu().findItem(R.id.nav_stats);
    if (ProSettings.checkEnabled(ProSettings.STATISTICS_KEY)) stats.setVisible(true);
    else stats.setVisible(false);

    MenuItem notes = navigationView.getMenu().findItem(R.id.nav_notes);
    if (ProSettings.checkEnabled(ProSettings.NOTES_KEY)) notes.setVisible(true);
    else notes.setVisible(false);

    if (updateFavorites) {
      SubMenu fab_menu = navigationView.getMenu().findItem(R.id.nav_header_favorites).getSubMenu();
      fab_menu.clear();

      Sites favorites = dataManager.getFavoriteSites();
      for (Site site : favorites) {
        MenuItem mi = fab_menu.add(2, site.code, Menu.NONE, site.name);
        configureMenuItem(mi, site);
      }
    }
    navigationView.invalidate();
  }
 public int navigationDrawer() {
   for (int i = 0; i < mNavigationView.getMenu().size(); i++) {
     final MenuItem menuItem = mNavigationView.getMenu().getItem(i);
     if (menuItem.isChecked()) {
       return menuItem.getItemId();
     }
   }
   return -1;
 }
Exemplo n.º 3
0
 private void enableDisableMenuItem(boolean enable) {
   if (enable) {
     navigationView.getMenu().findItem(R.id.restore).setTitle("Restore");
     navigationView.getMenu().findItem(R.id.backup).setTitle("Backup");
   } else {
     navigationView.getMenu().findItem(R.id.restore).setTitle("Restore (Disabled)");
     navigationView.getMenu().findItem(R.id.backup).setTitle("Backup (Disabled)");
   }
   navigationView.getMenu().findItem(R.id.restore).setEnabled(enable);
   navigationView.getMenu().findItem(R.id.backup).setEnabled(enable);
 }
Exemplo n.º 4
0
  @Override
  public void onBackPressed() {

    // if drawer is open first close drawer
    if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
      drawerLayout.closeDrawer(Gravity.LEFT);
    } else {

      int backStackCount = getSupportFragmentManager().getBackStackEntryCount();

      if (backStackCount == 0) {
        // nothing exist in backStack OS handle it
        super.onBackPressed();
      } else {

        getSupportFragmentManager().popBackStack();

        if (!titleStack.isEmpty()) {
          toolbarTitle.setText(titleStack.pop());
        }

        if (backStackCount == 1) {
          previousMenuItem = navigationView.getMenu().findItem(R.id.nav_category);
          previousMenuItem.setChecked(true);
          previousMenuItem.setCheckable(true);
        }
      }
    }
  }
Exemplo n.º 5
0
 @Override
 protected void onRestoreInstanceState(Bundle savedInstanceState) {
   super.onRestoreInstanceState(savedInstanceState);
   mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION, 0);
   Menu menu = navigationView.getMenu();
   menu.getItem(mCurrentSelectedPosition).setChecked(true);
 }
Exemplo n.º 6
0
  private void initNavigation() {
    drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    drawerToggle =
        new ActionBarDrawerToggle(
            MainActivity.this, drawerLayout, R.string.hello_world, R.string.hello_world);
    drawerLayout.setDrawerListener(drawerToggle);

    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation);
    navigationView.setNavigationItemSelectedListener(new MyOnNavItemListener());
    navMenu = navigationView.getMenu();
    navMenu.getItem(0).setChecked(true);

    sharedPreferences = getSharedPreferences(SpConfig.Name, Context.MODE_PRIVATE);
    String icon = sharedPreferences.getString(SpConfig.PERSON_ICON, "");

    TextView navName = (TextView) navigationView.findViewById(R.id.nav_header_name);
    String name = sharedPreferences.getString(SpConfig.PERSON_NAME, "");
    navName.setText(name);

    ImageView navIcon = (ImageView) navigationView.findViewById(R.id.nav_header_icon);
    ImageHelper imageHelper = ImageHelper.getInstance(getApplicationContext());
    imageHelper.loadCircleImage(navIcon, icon, 120);

    String portalName = sharedPreferences.getString(SpConfig.P_NAME, "");
    String portalPw = sharedPreferences.getString(SpConfig.P_PW, "");
    portalHelper = new PortalHelper(getApplicationContext());
    if (StringUtil.isNull(portalName) || StringUtil.isNull(portalPw)) {
      navMenu.getItem(2).setVisible(false);
    } else {
      portalHelper.info(new PortalInfo());
    }
  }
 @Override
 public void onNavigationDrawerItemSelected(int itemId) {
   MenuItem item = mNavigationView.getMenu().findItem(itemId);
   if (item != null) {
     item.setChecked(true);
   }
 }
Exemplo n.º 8
0
  public static void goTo(String code) {

    replaceFragment(sf);
    currentFragment = sf;

    assert (actionBar != null);

    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setTitle(R.string.title_activity_main);

    ScheduleFragment.user = Framework.MY_SCHEDULE;
    UpdateSchedule.dayOfWeek = DayPicker.toDayNumber(cal.get(Calendar.DAY_OF_WEEK));
    ScheduleFragment.setWeekUnix((int) (System.currentTimeMillis() / 1000));
    UpdateSchedule.scroll = true;
    ScheduleFragment.createList();
    datePickerButton.setVisibility(View.VISIBLE);
    menu.findItem(R.id.menu_search).setVisible(true);

    navigationView.getMenu().getItem(0).setChecked(true);
    if (ScheduleFragment.classArrayList.size() == 0) {
      progressBar.setVisibility(View.VISIBLE);
    }

    ScheduleFragment.user = code;
    goToday();

    actionBar.invalidateOptionsMenu();
  }
Exemplo n.º 9
0
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    if (mDrawerLayout != null) {
      // Load saved navigation state if present
      if (null == savedInstanceState) {
        mNavItemId = R.id.drawer_contact;
      } else {
        mNavItemId = savedInstanceState.getInt(NAV_ITEM_ID);
      }

      // Listen for navigation events
      NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
      navigationView.setNavigationItemSelectedListener(this);

      // Select the correct nav menu item
      navigationView.getMenu().findItem(mNavItemId).setChecked(true);

      // Initialize the Toolbar
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setupToolbar(toolbar);

      // Load the selected fragment
      navigate(mNavItemId);
    }
  }
Exemplo n.º 10
0
  private void addFolderToNavView(int id, String name, int icon) {

    Menu menu = navigationView.getMenu();
    addMenuCustomItem(menu, id, 11, name, icon, 0);

    openFolderWithNotes(id);
  }
Exemplo n.º 11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_container);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    navigationView.getMenu().getItem(0).setChecked(true);
    displayView(0);
  }
  public boolean navigationDrawer(final int itemId) {
    // <https://stackoverflow.com/q/30752713/>
    if (!alive() || transitioning()) {
      LogHelper.warning("Switching Fragments too early");
      return false;
    }
    transitioning(true);

    // Clears any loading state and capability
    refreshable(false, null);

    // Switch Fragment
    final SkeletonFragment skeletonFragment = getFragment(itemId);
    if (skeletonFragment == null) {
      LogHelper.warning("SkeletonFragment was NULL");
      transitioning(false);
      return false;
    }

    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.sk_frameLayout, skeletonFragment)
        .addToBackStack(null)
        .commit();

    // Updates NavigationDrawer
    final MenuItem menuItem = mNavigationView.getMenu().findItem(itemId);
    if (menuItem != null) {
      menuItem.setChecked(true);
    }
    closeNavigationDrawer();
    onNavigationDrawerClosed();

    return true;
  }
Exemplo n.º 13
0
  @Override
  public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
    String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK);
    FragmentManager fm = getSupportFragmentManager();
    currentFragment = (SubsonicFragment) fm.findFragmentByTag(ids[0]);
    currentFragment.setPrimaryFragment(true);
    currentFragment.setSupportTag(ids[0]);
    supportInvalidateOptionsMenu();
    FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    for (int i = 1; i < size; i++) {
      SubsonicFragment frag = (SubsonicFragment) fm.findFragmentByTag(ids[i]);
      frag.setSupportTag(ids[i]);
      if (secondaryContainer != null) {
        frag.setPrimaryFragment(false, true);
      }
      trans.hide(frag);
      backStack.add(frag);
    }
    trans.commit();

    // Current fragment is hidden in secondaryContainer
    if (secondaryContainer == null && !currentFragment.isVisible()) {
      trans = getSupportFragmentManager().beginTransaction();
      trans.remove(currentFragment);
      trans.commit();
      getSupportFragmentManager().executePendingTransactions();

      trans = getSupportFragmentManager().beginTransaction();
      trans.add(R.id.fragment_container, currentFragment, ids[0]);
      trans.commit();
    }
    // Current fragment needs to be moved over to secondaryContainer
    else if (secondaryContainer != null
        && secondaryContainer.findViewById(currentFragment.getRootId()) == null
        && backStack.size() > 0) {
      trans = getSupportFragmentManager().beginTransaction();
      trans.remove(currentFragment);
      trans.show(backStack.get(backStack.size() - 1));
      trans.commit();
      getSupportFragmentManager().executePendingTransactions();

      trans = getSupportFragmentManager().beginTransaction();
      trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
      trans.commit();

      secondaryContainer.setVisibility(View.VISIBLE);
    }

    lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
    if (lastSelectedPosition != 0) {
      MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
      if (item != null) {
        item.setChecked(true);
      }
    }
    recreateSpinner();
  }
Exemplo n.º 14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ButterKnife.bind(this);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle =
        new ActionBarDrawerToggle(
            this,
            drawer,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    menu = navigationView.getMenu();

    // Load menu
    //   deleteDatabase("sub_reddit-db");
    DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "sub_reddit-db", null);
    SQLiteDatabase db = helper.getWritableDatabase();
    DaoMaster daoMaster = new DaoMaster(db);
    DaoSession daoSession = daoMaster.newSession();
    SubRedditDao subRedditDao = daoSession.getSubRedditDao();
    menuList = subRedditDao.loadAll();
    if (menuList.size() == 0) { // init
      Log.i("MyTag", "Subreddit init - list was empty");
      subRedditDao.insert(new SubReddit(null, "art", "art"));
      subRedditDao.insert(new SubReddit(null, "belgium", "belgium"));
      subRedditDao.insert(new SubReddit(null, "gifs", "gifs"));
      subRedditDao.insert(new SubReddit(null, "funny", "funny"));
      subRedditDao.insert(new SubReddit(null, "pics", "pics"));
      subRedditDao.insert(new SubReddit(null, "diy", "diy"));
      menuList = subRedditDao.loadAll();
    }
    // Dynamicly load menu
    for (SubReddit item : menuList) {
      menu.add(R.id.menuSubreddit, menuList.indexOf(item), Menu.NONE, item.getTitle());
    }

    // Load fragment
    Bundle bundle = new Bundle();
    bundle.putLong("subRedditId", menuList.get(0).getId());
    Fragment fragment = new SubRedditListFragment();
    fragment.setArguments(bundle);
    getSupportFragmentManager()
        .beginTransaction()
        .add(R.id.frameLayoutMain, fragment)
        .addToBackStack(null)
        .commit();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_navigation_drawer);

    ButterKnife.bind(this);
    //        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //        setSupportActionBar(toolbar);
    // Set a Toolbar to replace the ActionBar.

    //        usernameprofile = (TextView) findViewById(R.id.usernameprofile);

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

    //        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    //        fab.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View view) {
    //                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
    //                        .setAction("Action", null).show();
    //            }
    //        });

    //        textView = (TextView) findViewById(R.id.textView);

    dlDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    navDrawer = (NavigationView) findViewById(R.id.nvView);
    drawerToggle = setupDrawerToggle();
    dlDrawer.setDrawerListener(drawerToggle);
    setupDrawerContent(navDrawer);

    //
    //
    //
    //        navDrawer.getMenu().getItem(0).setChecked(true);
    //
    //        FragmentManager manager = getSupportFragmentManager();
    //        manager.beginTransaction().replace(R.id.flContent, new HomeFragment()).commit();
    //        setTitle(R.id.about);

    dlDrawer.setDrawerListener(drawerToggle);
    navDrawer.getMenu().getItem(0).setChecked(true);
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.flContent, new HomeFragment()).commit();
    setTitle(R.string.home);

    // Fetching email from shared preferences
    SharedPreferences sharedPreferences =
        getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
    String username = sharedPreferences.getString(Config.USERNAME_SHARED_PREF, "Not Available");

    // Display a user Details Inside the Navigation Drawer Header

    //
    //        //showing the current Username
    usernameprofile.setText("username:" + username);
  }
Exemplo n.º 16
0
 private void countBackup() {
   if (navigationView.getMenu() != null) {
     if (navigationView.getMenu().findItem(R.id.restore) != null) {
       int count = AppHelper.getRestoreApksCount();
       if (count != 0) {
         navigationView
             .getMenu()
             .findItem(R.id.restore)
             .setTitle(getString(R.string.restore_title) + " ( " + count + " )");
       } else {
         navigationView
             .getMenu()
             .findItem(R.id.restore)
             .setTitle(getString(R.string.restore_title));
       }
     }
   }
 }
Exemplo n.º 17
0
 private void handleNoteMoveAction(boolean actionBarMenuItemClicked) {
   Dialog dialog =
       Utils.getFolderListDialog(
           this,
           navigationView.getMenu(),
           new int[] {folderId, trashNavId},
           getString(R.string.choose_new_folder),
           getMoveNoteToOtherFolderAction(actionBarMenuItemClicked));
   if (dialog != null) dialog.show();
 }
  @Override
  protected void onPostResume() {
    super.onPostResume();
    mDrawerToggle.syncState();

    final MenuItem menuItem = mNavigationView.getMenu().getItem(0);
    if (menuItem != null) {
      navigationDrawer(menuItem.getItemId());
    }
  }
  private void initNavDrawer() {
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle =
        new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.app_name, R.string.app_name) {
          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
          }

          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
          }

          @Override
          public boolean onOptionsItemSelected(MenuItem item) {
            if (item != null && item.getItemId() == android.R.id.home) {
              if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
                drawerLayout.closeDrawer(Gravity.LEFT);
              } else drawerLayout.openDrawer(Gravity.LEFT);
            }
            return false;
          }
        };
    drawerLayout.setDrawerListener(drawerToggle);
    navigationView = (NavigationView) findViewById(R.id.navigation);
    navigationView
        .getMenu()
        .findItem(R.id.my_cart)
        .setTitle("" + PreferenceManager.getName() + "'s Cart");
    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {
            drawerLayout.closeDrawers();
            menuItem.setChecked(true);
            switch (menuItem.getItemId()) {
              case R.id.my_cart:
                loadMyCartFragment();
                break;
              case R.id.order_history:
                break;
              case R.id.about_us:
                break;
              case R.id.logout:
                logout();
                break;
            }
            return true;
          }
        });
    drawerToggle.syncState();
  }
Exemplo n.º 20
0
  @Override
  public void loggedIn(User user) {

    UiUtils.hideKeyboard(mainActivity);

    Menu menu = mNavigationView.getMenu();
    menu.findItem(R.id.drawer_item_logout).setVisible(true);

    mHeaderLoggedIn.setVisibility(View.VISIBLE);
    mUsernameLoggedIn.setText(user.getUsername());
  }
Exemplo n.º 21
0
  @SuppressWarnings("ConstantConditions")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set a Toolbar to replace the ActionBar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Find our drawer view
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawerToggle =
        new ActionBarDrawerToggle(this, mDrawer, R.string.drawer_open, R.string.drawer_closed) {
          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            invalidateOptionsMenu();
          }

          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            Log.d(TAG, "onDrawerClosed: " + getTitle());

            invalidateOptionsMenu();
          }
        };

    mDrawer.setDrawerListener(mDrawerToggle);

    // Find our drawer view
    NavigationView nvDrawer = (NavigationView) findViewById(R.id.nvView);

    // Setup drawer view
    setupDrawerContent(nvDrawer);

    // Handle for menu
    menu = nvDrawer.getMenu();

    // Insert the home fragment
    FragmentManager fragmentManager = getSupportFragmentManager();
    try {
      FragmentTransaction transaction = fragmentManager.beginTransaction();
      transaction.addToBackStack(null);
      transaction.replace(R.id.flContent, HungryHome.class.newInstance()).commit();
    } catch (InstantiationException | IllegalAccessException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 22
0
  private void setMenuItemCheck(MenuItem menuItem) {

    int currentGroupId = menuItem.getGroupId();
    ArrayList<Integer> allGroupsIds =
        new ArrayList<Integer>() {
          {
            add(R.id.top);
            add(R.id.bottom);
          }
        };

    for (int i = 0; i < allGroupsIds.size(); ++i) {

      if (currentGroupId == allGroupsIds.get(i)) {
        navigationView.getMenu().setGroupCheckable(allGroupsIds.get(i), true, true);
      } else {
        navigationView.getMenu().setGroupCheckable(allGroupsIds.get(i), false, true);
      }
    }
    menuItem.setChecked(true);
  }
Exemplo n.º 23
0
  private void setNoteTitleOrFolderName(String title) {
    title = setTitle(title);

    if (fragmentManager.findFragmentByTag(Constants.FRAGMENT_NOTE)
        != null) // Note fragment is displayed
    ((NoteFragment) fragmentManager.findFragmentByTag(Constants.FRAGMENT_NOTE)).titleChanged(title);
    else if (fragmentManager.findFragmentByTag(Constants.FRAGMENT_LIST) != null) {
      ((NoteListFragment) fragmentManager.findFragmentByTag(Constants.FRAGMENT_LIST))
          .titleChanged(title);
      navigationView.getMenu().findItem(folderId).setTitle(title);
    }
  }
  private void setupDrawerContent(final NavigationView navigationView) {

    MenuItem item = navigationView.getMenu().getItem(0);
    item.setChecked(true);
    prevItem = item;

    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem item) {

            prevItem.setChecked(false);
            prevItem = item;

            switch (item.getItemId()) {
              case R.id.home_page:
                toolbar.setTitle("Welcome");
                transitionTo(DemoHomePageFragment.newInstance());
                break;
              case R.id.recommendations:
                toolbar.setTitle(getString(R.string.demo_recommendations));
                transitionTo(DemoRecommendationsFragment.newInstance());
                break;
              case R.id.advertising:
                toolbar.setTitle("Advertising");
                transitionTo(AdsFragment.newInstance());
                break;
              case R.id.conversations_demo:
                toolbar.setTitle(getString(R.string.demo_conversations) + ": API Demo");
                transitionTo(DemoConversationsAPIFragment.newInstance());
                break;
              case R.id.conversations_demo_stores:
                toolbar.setTitle(getString(R.string.demo_conversations_stores) + ": API Demo");
                transitionTo(DemoConversationsStoresAPIFragment.newInstance());
                break;
              case R.id.curations:
                toolbar.setTitle(getString(R.string.demo_curations));
                transitionTo(DemoCurationsFragment.newInstance());
                break;
              case R.id.location:
                toolbar.setTitle(getString(R.string.demo_location));
                transitionTo(DemoLocationFragment.newInstance());
            }

            // Close the navigation drawer when an item is selected.
            item.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
          }
        });
  }
Exemplo n.º 25
0
  private void populateServers() {
    drawerList.getMenu().clear();

    int serverCount = Util.getServerCount(this);
    int activeServer = Util.getActiveServer(this);
    for (int i = 1; i <= serverCount; i++) {
      MenuItem item =
          drawerList
              .getMenu()
              .add(
                  MENU_GROUP_SERVER,
                  MENU_ITEM_SERVER_BASE + i,
                  MENU_ITEM_SERVER_BASE + i,
                  Util.getServerName(this, i));
      if (activeServer == i) {
        item.setChecked(true);
      }
    }
    drawerList.getMenu().setGroupCheckable(MENU_GROUP_SERVER, true, true);
    drawerHeaderToggle.setImageResource(R.drawable.main_select_tabs_dark);

    showingTabs = false;
  }
Exemplo n.º 26
0
 @Override
 protected void onResume() {
   super.onResume();
   assert getSupportActionBar() != null;
   // Check if ActionBar subtitle should be displayed
   if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_subtitle", true)) {
     getSupportActionBar().setSubtitle(null);
   }
   // Reselect the current fragment in order to update action bar and floating action button
   if (isOnline()) {
     MenuItem m = sNavView.getMenu().findItem(sCurrentFragment);
     selectDrawerItem(m);
   }
 }
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    UIUtils.showUserData(menu, this, null);

    Menu drawerMenu = navigationView.getMenu();
    MenuItem itemLogout = drawerMenu.findItem(R.id.menu_logout);
    MenuItem itemSettings = drawerMenu.findItem(R.id.menu_settings);
    MenuItem itemMonitor = drawerMenu.findItem(R.id.menu_monitor);
    MenuItem itemCourseDownload = drawerMenu.findItem(R.id.menu_download);

    itemLogout.setVisible(
        prefs.getBoolean(PrefsActivity.PREF_LOGOUT_ENABLED, MobileLearning.MENU_ALLOW_LOGOUT));
    itemSettings.setVisible(MobileLearning.MENU_ALLOW_SETTINGS);
    itemMonitor.setVisible(MobileLearning.MENU_ALLOW_MONITOR);
    itemCourseDownload.setVisible(MobileLearning.MENU_ALLOW_COURSE_DOWNLOAD);

    return super.onPrepareOptionsMenu(menu);
  }
Exemplo n.º 28
0
  private void setupDrawerContent() {
    // set category item as default
    previousMenuItem = navigationView.getMenu().findItem(R.id.nav_category);
    previousMenuItem.setChecked(true);
    previousMenuItem.setCheckable(true);

    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {

            drawerLayout.closeDrawer(Gravity.LEFT);

            if (previousMenuItem.getItemId() == menuItem.getItemId()) return true;

            menuItem.setCheckable(true);
            menuItem.setChecked(true);
            previousMenuItem.setChecked(false);
            previousMenuItem = menuItem;

            switch (menuItem.getItemId()) {
              case R.id.nav_category:
                displayView(CATEGORIES_FRAG, null);
                break;
              case R.id.nav_favorites:
                displayView(FAVORITE_FRAG, null);
                break;
              case R.id.nav_about:
                displayView(ABOUT_FRAG, null);
                break;
              case R.id.nav_feedback:
                displayView(LEARNING_FRAG, null);
                break;
              case R.id.nav_settings:
                displayView(SETTINGS_FRAG, null);
                break;
            }

            return true;
          }
        });
  }
Exemplo n.º 29
0
  public NavigationDrawer(MainActivity activity, View view) {
    ButterKnife.bind(this, view);
    activity.inject(this);

    mainActivity = activity;

    mViewModel.setListener(this);

    Menu menu = mNavigationView.getMenu();
    new MenuItemCommandBinding()
        .bind(menu.findItem(R.id.drawer_item_news), mViewModel.getNavigateToNewsCommand());
    new MenuItemCommandBinding()
        .bind(
            menu.findItem(R.id.drawer_item_productsearch),
            mViewModel.getNavigateToProductSearchCommand());
    new MenuItemCommandBinding()
        .bind(
            menu.findItem(R.id.drawer_item_categorysearch),
            mViewModel.getNavigateToCategorySearchCommand());
    new MenuItemCommandBinding()
        .bind(
            menu.findItem(R.id.drawer_item_scanner),
            mViewModel.getNavigateToBarcodeScannerCommand());
    new MenuItemCommandBinding()
        .bind(menu.findItem(R.id.drawer_item_inventory), mViewModel.getInventoryCommand());
    new MenuItemCommandBinding()
        .bind(
            menu.findItem(R.id.drawer_item_reservation),
            mViewModel.getNavigateToReservationCommand());
    new MenuItemCommandBinding()
        .bind(menu.findItem(R.id.drawer_item_alert), mViewModel.getNavigateToAlertCommand());
    new MenuItemCommandBinding()
        .bind(menu.findItem(R.id.drawer_item_about), mViewModel.getNavigateToAboutCommand());
    new MenuItemCommandBinding()
        .bind(menu.findItem(R.id.drawer_item_settings), mViewModel.getNavigateToSettingsCommand());
    new MenuItemCommandBinding()
        .bind(menu.findItem(R.id.drawer_item_logout), mViewModel.getLogoutCommand());
    new MenuItemCommandBinding()
        .bind(menu.findItem(R.id.drawer_item_projects), mViewModel.getNavigateToProjectsCommand());

    menu.findItem(R.id.drawer_item_logout).setVisible(false);
  }
Exemplo n.º 30
0
  private void addFolderToNavView(Cursor cursor) {
    Menu menu = navigationView.getMenu();

    if (menu.size() != 0) Utils.removeAllMenuItems(menu);

    navigationView.inflateMenu(R.menu.activity_main_drawer);

    for (int i = 0; i < cursor.getCount(); i++) {
      Log.e(
          TAG,
          " "
              + cursor.getString(cursor.getColumnIndexOrThrow(Constants.FOLDER_NAME_COL))
              + ",  "
              + cursor.getString(cursor.getColumnIndexOrThrow(Constants.NOTES_COUNT_COL)));

      int id = cursor.getInt(cursor.getColumnIndexOrThrow(Constants.ID_COL));
      int order = 11;
      int count = cursor.getInt(cursor.getColumnIndexOrThrow(Constants.NOTES_COUNT_COL));
      if (id == myNotesNavId) order = 10;
      else if (id == trashNavId) {
        order = 10000;
        count = deletedCount;
      }

      addMenuCustomItem(
          menu,
          id,
          order,
          cursor.getString(cursor.getColumnIndexOrThrow(Constants.FOLDER_NAME_COL)),
          cursor.getInt(cursor.getColumnIndexOrThrow(Constants.FOLDER_ICON_COL)),
          count);
      cursor.moveToNext();
    }
    cursor.close();

    if (menu.findItem(folderId) == null) folderId = myNotesNavId;

    navigationView.setCheckedItem(folderId);

    attachFragment(Constants.FRAGMENT_LIST);
  }