androidx.navigation.NavDestination Java Examples
The following examples show how to use
androidx.navigation.NavDestination.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LttrsActivity.java From lttrs-android with Apache License 2.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: final NavController navController = Navigation.findNavController( this, R.id.nav_host_fragment ); final NavDestination currentDestination = navController.getCurrentDestination(); if (currentDestination != null && MAIN_DESTINATIONS.contains(currentDestination.getId())) { binding.drawerLayout.openDrawer(GravityCompat.START); return true; } else { onBackPressed(); } } return super.onOptionsItemSelected(item); }
Example #2
Source File: NavigationUI.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Determines whether the given <code>destId</code> matches the NavDestination. This handles * both the default case (the destination's id matches the given id) and the nested case where * the given id is a parent/grandparent/etc of the destination. */ private static boolean matchDestination(@NonNull NavDestination destination, @IdRes int destId) { NavDestination currentDestination = destination; while (currentDestination.getId() != destId && currentDestination.getParent() != null) { currentDestination = currentDestination.getParent(); } return currentDestination.getId() == destId; }
Example #3
Source File: NavigationUI.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Finds the actual start destination of the graph, handling cases where the graph's starting * destination is itself a NavGraph. */ private static NavDestination findStartDestination(@NonNull NavGraph graph) { NavDestination startDestination = graph; while (startDestination instanceof NavGraph) { NavGraph parent = (NavGraph) startDestination; startDestination = parent.findNode(parent.getStartDestination()); } return startDestination; }
Example #4
Source File: NavigationUI.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public void onNavigated(@NonNull NavController controller, @NonNull NavDestination destination) { ActionBar actionBar = mActivity.getSupportActionBar(); CharSequence title = destination.getLabel(); if (!TextUtils.isEmpty(title)) { actionBar.setTitle(title); } boolean isStartDestination = findStartDestination(controller.getGraph()) == destination; actionBar.setDisplayHomeAsUpEnabled(mDrawerLayout != null || !isStartDestination); setActionBarUpIndicator(mDrawerLayout != null && isStartDestination); }
Example #5
Source File: LttrsActivity.java From lttrs-android with Apache License 2.0 | 5 votes |
private int getCurrentDestinationId() { final NavController navController = Navigation.findNavController( this, R.id.nav_host_fragment ); final NavDestination currentDestination = navController.getCurrentDestination(); return currentDestination == null ? 0 : currentDestination.getId(); }
Example #6
Source File: LttrsActivity.java From lttrs-android with Apache License 2.0 | 5 votes |
private void configureActionBarForDestination(NavDestination destination) { final ActionBar actionbar = getSupportActionBar(); if (actionbar == null) { return; } final int destinationId = destination.getId(); final boolean showMenu = MAIN_DESTINATIONS.contains(destinationId); actionbar.setDisplayHomeAsUpEnabled(true); actionbar.setHomeAsUpIndicator(showMenu ? R.drawable.ic_menu_black_24dp : R.drawable.ic_arrow_back_white_24dp); actionbar.setDisplayShowTitleEnabled(destinationId != R.id.thread); }
Example #7
Source File: LttrsActivity.java From lttrs-android with Apache License 2.0 | 5 votes |
@Override public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) { LOGGER.debug("onDestinationChanged({})", destination.getLabel()); if (destination.getId() == R.id.thread) { endActionMode(); } configureActionBarForDestination(destination); }
Example #8
Source File: MainActivity.java From ground-android with Apache License 2.0 | 5 votes |
private int getCurrentNavDestinationId() { NavDestination destination = getNavController().getCurrentDestination(); if (destination == null) { return -1; } return destination.getId(); }
Example #9
Source File: NavigationActivity.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.navigation_activity); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); NavHostFragment host = (NavHostFragment) getSupportFragmentManager() .findFragmentById(R.id.my_nav_host_fragment); if (host != null) { NavController navController = host.getNavController(); mDrawerLayout = findViewById(R.id.drawer_layout); NavigationUI.setupActionBarWithNavController(this, navController, mDrawerLayout); NavigationView navigationView = findViewById(R.id.nav_view); if (navigationView != null) { NavigationUI.setupWithNavController(navigationView, navController); } BottomNavigationView bottomNavView = findViewById(R.id.bottom_nav_view); if (bottomNavView != null) { NavigationUI.setupWithNavController(bottomNavView, navController); } navController.addOnNavigatedListener(new NavController.OnNavigatedListener() { @Override public void onNavigated(@NonNull NavController controller, @NonNull NavDestination destination) { String dest; try { dest = getResources().getResourceName(destination.getId()); } catch (Resources.NotFoundException e) { dest = Integer.toString(destination.getId()); } Toast.makeText(NavigationActivity.this, "Navigated to " + dest, Toast.LENGTH_SHORT).show(); Log.d("NavigationActivity", "Navigated to " + dest); } }); } }
Example #10
Source File: TestNavigator.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * NavDestinations should be created via {@link Navigator#createDestination}. */ Destination(@NonNull Navigator<? extends NavDestination> navigator) { super(navigator); }