Java Code Examples for androidx.drawerlayout.widget.DrawerLayout#closeDrawer()

The following examples show how to use androidx.drawerlayout.widget.DrawerLayout#closeDrawer() . 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: DrawerLayoutActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Closes the drawer at the specified edge gravity. */
public static ViewAction closeDrawer(final int drawerEdgeGravity) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(DrawerLayout.class);
    }

    @Override
    public String getDescription() {
      return "Closes the drawer";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();

      DrawerLayout drawerLayout = (DrawerLayout) view;
      drawerLayout.closeDrawer(drawerEdgeGravity);

      // Wait for a full second to let the inner ViewDragHelper complete the operation
      uiController.loopMainThreadForAtLeast(1000);
    }
  };
}
 
Example 2
Source File: MainActivity.java    From ArcNavigationView with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else if (drawer.isDrawerOpen(GravityCompat.END)) {
        drawer.closeDrawer(GravityCompat.END);
    } else {
        super.onBackPressed();
    }
}
 
Example 3
Source File: MainActivity.java    From DeAutherDroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    if (!mainRender.canGoBack()) {
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    } else {
        mainRender.goBack();
    }
}
 
Example 4
Source File: MainActivity.java    From guanggoo-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    switch (item.getItemId()) {
        case R.id.nav_user_profile:
            openUserProfile();
            break;

        case R.id.nav_favors:
            openPage(String.format(ConstantUtil.USER_FAVORS_BASE_URL, AuthInfoManager.getInstance().getUsername()), getString(R.string.my_favors));
            break;

        case R.id.nav_nodes:
            openPage(ConstantUtil.NODES_CLOUD_URL, getString(R.string.nodes_list));
            break;

        case R.id.nav_beginner_guide:
            openPage(ConstantUtil.BEGINNER_GUIDE_URL, getString(R.string.beginner_guide));
            break;

        case R.id.nav_about:
            openPage(ConstantUtil.ABOUT_URL, getString(R.string.about));
            break;

        default:
            break;
    }

    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 5
Source File: MainActivity.java    From GooglePlayCloned with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example 6
Source File: MainActivity.java    From android-biometricprompt with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example 7
Source File: MainActivity.java    From busybox with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            drawer.openDrawer(GravityCompat.START);
        }
    } else {
        return super.onOptionsItemSelected(item);
    }
    return false;
}
 
Example 8
Source File: NavigationDrawer.java    From Open-Source-Android-Weather-App with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    Log.d("start", ">>> Navigation Bar");
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example 9
Source File: OverScrollDemoActivity.java    From overscroll-decor with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example 10
Source File: MainActivity.java    From ns-usbloader-mobile with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    final DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START))
        drawer.closeDrawer(GravityCompat.START);
    else
        super.onBackPressed();
}
 
Example 11
Source File: DriverHome.java    From UberClone with MIT License 5 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    switch (id){
        case R.id.nav_trip_history:
            showTripHistory();
            break;
        case R.id.nav_car_type:
            showDialogUpdateCarType();
            break;
        case R.id.nav_update_info:
            showDialogUpdateInfo();
            break;
        case R.id.nav_change_pwd:
            if(account!=null)
                showDialogChangePwd();
            break;
        case R.id.nav_sign_out:
            signOut();
            break;
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 12
Source File: MainActivity.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else if (mWebView.canGoBack()) {
        mWebView.goBack();
    } else {
        super.onBackPressed();
    }
}
 
Example 13
Source File: MainActivity.java    From MaterialTapTargetPrompt with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed()
{
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START))
    {
        drawer.closeDrawer(GravityCompat.START);
    }
    else
    {
        super.onBackPressed();
    }
}
 
Example 14
Source File: MainActivity.java    From android-app with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example 15
Source File: MainActivity.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Close drawer if open otherwise go to app home screen.
 */
@Override
public void onBackPressed()
{
	DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
	if (drawer.isDrawerOpen(GravityCompat.START))
	{
		drawer.closeDrawer(GravityCompat.START);
	}
	else
	{
		moveTaskToBack(true);
	}
}
 
Example 16
Source File: MainActivity.java    From android with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example 17
Source File: EditorActivity.java    From APDE with GNU General Public License v2.0 4 votes vote down vote up
@Override
 public boolean onOptionsItemSelected(MenuItem item) {
 	//When an action bar (or action bar overflow) action has been selected
 	
     switch(item.getItemId()) {
     	case android.R.id.home:
     		//The drawer toggle button
     		
     		//Get a reference to the drawer views
     		DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer);
     		RelativeLayout drawerLayout = (RelativeLayout) findViewById(R.id.drawer_wrapper);
     		
     		if(drawer.isDrawerOpen(drawerLayout)) {
     			//If the drawer is open, close it
                 drawer.closeDrawer(drawerLayout);
     		} else {
     			//If the drawer is closed, open it
                 drawer.openDrawer(drawerLayout);
                 
                 //Turn of the code area so that it cannot be focused (and so that the soft keyboard is hidden)
		if (isSelectedCodeAreaInitialized()) {
			getSelectedCodeArea().setEnabled(false);
		}
                 supportInvalidateOptionsMenu();
             }
     		return true;
case R.id.menu_comp_select_app:
	setComponentTarget(ComponentTarget.APP);
	return true;
case R.id.menu_comp_select_wallpaper:
	setComponentTarget(ComponentTarget.WALLPAPER);
	return true;
case R.id.menu_comp_select_watchface:
	setComponentTarget(ComponentTarget.WATCHFACE);
	return true;
case R.id.menu_comp_select_vr:
	setComponentTarget(ComponentTarget.VR);
	return true;
case R.id.menu_comp_select_preview:
	setComponentTarget(ComponentTarget.PREVIEW);
	return true;
         case R.id.menu_undo:
     		tabs.get(getSelectedCodeIndex()).undo(this);
         	return true;
         case R.id.menu_redo:
         	tabs.get(getSelectedCodeIndex()).redo(this);
         	return true;
         case R.id.menu_save:
         	saveSketch();
         	return true;
case R.id.menu_rename:
	launchRenameSketch();
	return true;
         case R.id.menu_copy_to_sketchbook:
         	copyToSketchbook();
         	return true;
case R.id.menu_move_to_sketchbook:
	moveToSketchbook();
	return true;
         case R.id.menu_new:
         	createNewSketch();
         	return true;
         case R.id.menu_load:
         	loadSketch();
         	return true;
case R.id.menu_delete:
	launchDeleteSketchConfirmationDialog();
	return true;
         case R.id.menu_settings:
         	launchSettings();
         	return true;
         case R.id.menu_tab_new:
         	addTabWithDialog();
         	return true;
         case R.id.menu_tab_rename:
         	renameTab();
         	return true;
         case R.id.menu_tab_delete:
         	deleteTab();
         	return true;
         case R.id.menu_tools:
         	launchTools();
     		return true;
         case R.id.menu_sketch_properties:
         	launchSketchProperties();
         	return true;
         default:
             return super.onOptionsItemSelected(item);
     }
 }
 
Example 18
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    View coordinatorLayout = findViewById(R.id.main_coordinator_layout);
    coordinatorLayout.setVisibility(View.VISIBLE);

    NowPlayingView nowPlayingView = findViewById(R.id.now_playing_layout);
    if (nowPlayingView != null) {
        nowPlayingView.minimize();
    }

    FragmentManager fragmentManager = getSupportFragmentManager();

    // clear backstack
    fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

    Fragment fragment = null;

    if (id == R.id.nav_my_music) {
        fragment = MyMusicFragment.newInstance(getDefaultTab());
    } else if (id == R.id.nav_saved_playlists) {
        fragment = SavedPlaylistsFragment.newInstance();
    } else if (id == R.id.nav_bookmarks) {
        fragment = BookmarksFragment.newInstance();
    } else if (id == R.id.nav_files) {
        // open the default directory
        List<String> storageVolumesList = mFileExplorerHelper.getStorageVolumes(getApplicationContext());

        String defaultDirectory = "/";

        if (!storageVolumesList.isEmpty()) {
            // choose the latest used storage volume as default
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
            defaultDirectory = sharedPref.getString(getString(R.string.pref_file_browser_root_dir_key), storageVolumesList.get(0));
        }

        fragment = FilesFragment.newInstance(defaultDirectory, storageVolumesList.contains(defaultDirectory));
    } else if (id == R.id.nav_settings) {
        fragment = SettingsFragment.newInstance();
    } else if (id == R.id.nav_information) {
        fragment = InformationSettingsFragment.newInstance();
    }

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer != null) {
        drawer.closeDrawer(GravityCompat.START);
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.fragment_container, fragment);
    transaction.commit();

    return true;
}
 
Example 19
Source File: MainActivity.java    From lbry-android with MIT License 4 votes vote down vote up
@Override
public void onBackPressed() {

    if (findViewById(R.id.url_suggestions_container).getVisibility() == View.VISIBLE) {
        clearWunderbarFocus(findViewById(R.id.wunderbar));
        return;
    }
    if (backPressInterceptor != null && backPressInterceptor.onBackPressed()) {
        return;
    }

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        boolean handled = false;
        // TODO: Refactor both forms as back press interceptors?
        ChannelFormFragment channelFormFragment = null;
        PublishFormFragment publishFormFragment = null;
        for (Fragment fragment : openNavFragments.values()) {
            if (fragment instanceof ChannelFormFragment) {
                channelFormFragment = ((ChannelFormFragment) fragment);
                break;
            }
            if (fragment instanceof PublishFormFragment) {
                publishFormFragment = ((PublishFormFragment) fragment);
                break;
            }
        }
        if (channelFormFragment != null && channelFormFragment.isSaveInProgress()) {
            handled = true;
            return;
        }
        if (publishFormFragment != null && (publishFormFragment.isSaveInProgress() || publishFormFragment.isTranscodeInProgress())) {
            if (publishFormFragment.isTranscodeInProgress()) {
                showMessage(R.string.transcode_in_progress);
            }
            handled = true;
            return;
        }

        if (!handled) {
            // check fragment and nav history
            FragmentManager manager = getSupportFragmentManager();
            int backCount = getSupportFragmentManager().getBackStackEntryCount();
            if (backCount > 0) {
                // we can pop the stack
                manager.popBackStack();
                setSelectedNavMenuItemForFragment(getCurrentFragment());
            } else if (!enterPIPMode()) {
                // we're at the top of the stack
                moveTaskToBack(true);
                return;
            }
        }
    }
}
 
Example 20
Source File: MainActivity.java    From lbry-android with MIT License 4 votes vote down vote up
private void closeDrawer() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
}