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

The following examples show how to use androidx.drawerlayout.widget.DrawerLayout#isDrawerOpen() . 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: MainUI.java    From Busybox-Installer-No-Root with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){

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

    if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){
        if(drawer.isDrawerOpen(GravityCompat.START)){
            switch(event.getAction()){
                case KeyEvent.ACTION_DOWN:
                    if(event.getDownTime() - lastPressedTime < PERIOD){
                        finish();
                    }else{
                        Toast.makeText(context, R.string.press_again_to_exit, Toast.LENGTH_SHORT).show();
                        lastPressedTime = event.getEventTime();
                    }
                    return true;
            }
        }else if(!drawer.isDrawerOpen(GravityCompat.START)){
            drawer.openDrawer(GravityCompat.START);
        }
    }
    return false;
}
 
Example 2
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 3
Source File: MainActivity.java    From android-news-app with MIT License 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 4
Source File: MainActivity.java    From Easer 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 {
        getSupportFragmentManager().popBackStack(0, 0); // The -1'st is the Outline. We rely on super.onBackPressed() to pop the 0th.
        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setCheckedItem(R.id.nav_outline);
        super.onBackPressed();
    }
}
 
Example 5
Source File: DrawerMatchers.java    From android-test with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a matcher that verifies that the drawer with the specified gravity is open. Matches
 * only when the drawer is fully open. Use {@link #isClosed(int)} instead of {@code not(isOpen())}
 * when you wish to check that the drawer is fully closed.
 */
public static Matcher<View> isOpen(final int gravity) {
  return new BoundedMatcher<View, DrawerLayout>(DrawerLayout.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("is drawer open");
    }

    @Override
    public boolean matchesSafely(DrawerLayout drawer) {
      return drawer.isDrawerOpen(gravity);
    }
  };
}
 
Example 6
Source File: MainActivity.java    From guanggoo-android with Apache License 2.0 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 {

        if (isLoading()) {
            stopLoading();
            return;
        }

        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
        if (fragment instanceof BaseFragment) {
            if (((BaseFragment) fragment).onBackPressed()) {
                return;
            }
        }

        if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
            long backPressTime = System.nanoTime();
            long oneSecondNano = 1000 * 1000 * 1000L;
            if (backPressTime - mLastBackPressTime > oneSecondNano) {
                Toast.makeText(this, getString(R.string.back_to_quit), Toast.LENGTH_SHORT).show();
            } else {
                finish();
            }
            mLastBackPressTime = backPressTime;
            return;
        }

        super.onBackPressed();
    }
}
 
Example 7
Source File: WebviewActivity.java    From WhatsappWebToGo with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    //close drawer if open and impl. press back again to leave
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else if (System.currentTimeMillis() - mLastBackClick < 1100) {
        finishAffinity();
    } else {
        mWebView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ESCAPE));
        showToast("Click back again to close");
        mLastBackClick = System.currentTimeMillis();
    }
}
 
Example 8
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 9
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 10
Source File: MainActivity.java    From iBeacon-Android with Apache License 2.0 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 11
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 12
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 13
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 14
Source File: Home.java    From UberClone 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 15
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 16
Source File: MainActivity.java    From CloudReader 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 17
Source File: MainActivity.java    From ui with Apache License 2.0 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 18
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 19
Source File: MainUI.java    From AnLinux-Adfree with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){

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

    Fragment fragment = this.getFragmentManager().findFragmentById(R.id.fragmentHolder);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();

    if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){
        if(fragment instanceof DashBoard){
            if(drawer.isDrawerOpen(GravityCompat.START)){
                switch(event.getAction()){
                    case KeyEvent.ACTION_DOWN:
                        if(event.getDownTime() - lastPressedTime < PERIOD){
                            finish();
                        }else{
                            Toast.makeText(context, R.string.press_again_to_exit, Toast.LENGTH_SHORT).show();
                            lastPressedTime = event.getEventTime();
                        }
                        return true;
                }
            }else if(!drawer.isDrawerOpen(GravityCompat.START)){
                drawer.openDrawer(GravityCompat.START);
            }
        }else if(fragment instanceof About){
            fragment = new DashBoard();
            fragmentTransaction.replace(R.id.fragmentHolder, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }else if(fragment instanceof DesktopEnvironment){
            fragment = new DashBoard();
            fragmentTransaction.replace(R.id.fragmentHolder, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }else if(fragment instanceof WindowManager){
            fragment = new DashBoard();
            fragmentTransaction.replace(R.id.fragmentHolder, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }else if(fragment instanceof SSH){
            fragment = new DashBoard();
            fragmentTransaction.replace(R.id.fragmentHolder, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }else if(fragment instanceof Uninstaller){
            fragment = new DashBoard();
            fragmentTransaction.replace(R.id.fragmentHolder, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }else if(fragment instanceof Patches){
            fragment = new DashBoard();
            fragmentTransaction.replace(R.id.fragmentHolder, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }else if(fragment instanceof SU){
            fragment = new DashBoard();
            fragmentTransaction.replace(R.id.fragmentHolder, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }else if(fragment instanceof RootfsDownload){
            fragment = new DashBoard();
            fragmentTransaction.replace(R.id.fragmentHolder, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
    }
    return false;
}
 
Example 20
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;
            }
        }
    }
}