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

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

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

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

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

      // Wait for a full second to let the inner ViewDragHelper complete the operation
      uiController.loopMainThreadForAtLeast(1000);
    }
  };
}
 
Example 3
Source File: DrawerActions.java    From android-test with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an action which opens the {@link DrawerLayout} drawer with the gravity. This method
 * blocks until the drawer is fully open. No operation if the drawer is already open.
 */
// TODO alias to openDrawer before 3.0 and deprecate this method.
public static ViewAction open(final int gravity) {
  return new DrawerAction() {
    @Override
    public String getDescription() {
      return "open drawer with gravity " + gravity;
    }

    @Override
    protected Matcher<View> checkAction() {
      return isClosed(gravity);
    }

    @Override
    protected void performAction(UiController uiController, DrawerLayout view) {
      view.openDrawer(gravity);
    }
  };
}
 
Example 4
Source File: SampleActivity.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.openDrawer(GravityCompat.START);
    drawer.clearAnimation();
    drawer.setAnimation(null);
    drawer.setLayoutAnimation(null);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.clearAnimation();
    navigationView.setAnimation(null);
    navigationView.setLayoutAnimation(null);

    bitmapView = findViewById(R.id.iv_image);
    bitmapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            bitmapView.setVisibility(View.GONE);
        }
    });

    rvImage = (RecyclerView) findViewById(R.id.rv_image);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    adapter = new MainAdapter(this, selectedPhotoList);
    rvImage.setLayoutManager(linearLayoutManager);
    rvImage.setAdapter(adapter);
    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(rvImage);
}
 
Example 5
Source File: DrawerLayoutActivity.java    From AndroidAll with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drawer_activity);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_right);
    drawerLayout.openDrawer(GravityCompat.END);
}
 
Example 6
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 7
Source File: EditorActivity.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Called when the user selects "Load Sketch" - this will open the navigation drawer
    */
   private void loadSketch() {
   	//Opens the navigation drawer
   	
	DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer);
	RelativeLayout drawerLayout = (RelativeLayout) findViewById(R.id.drawer_wrapper);
	
	drawer.openDrawer(drawerLayout);
}
 
Example 8
Source File: MainUI.java    From AnLinux-App 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 9
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 10
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);
     }
 }