@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    Boolean isDrawerOpen = mDrawerLayout.isDrawerOpen(Gravity.RIGHT);
    Boolean isMenuListFocused = false;
    if (mList != null) {
      isMenuListFocused = mList.hasFocus();
    }
    View view = this.getCurrentFocus();

    if (isDrawerOpen) {
      if (!view.getClass()
          .getName()
          .equalsIgnoreCase("com.android.internal.view.menu.ActionMenuItemView")) {
        mDrawerLayout.closeDrawers();
        mDrawerLayout.getChildAt(0).requestFocus();
      }
    } else {
      if (KeyEvent.KEYCODE_DPAD_UP == keyCode) {
        // action bar
        mDrawerLayout.getChildAt(1).requestFocus();
      } else if (KeyEvent.KEYCODE_DPAD_DOWN == keyCode) {
        // grid view
        mDrawerLayout.getChildAt(0).requestFocus();
      } else if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) {
      } else if (KeyEvent.KEYCODE_MENU == keyCode) {
        if (!mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
          mDrawerLayout.openDrawer(Gravity.RIGHT);
        } else {
          mDrawerLayout.closeDrawer(Gravity.RIGHT);
        }
      }
    }

    return super.onKeyDown(keyCode, event);
  }
 /** Checks whether or not any drawer is open in the DrawerActivity. */
 public final boolean isDrawerOpen() {
   DrawerLayout drawer = getDrawerLayout();
   return drawer != null
       && (drawer.isDrawerOpen(Gravity.START)
           || drawer.isDrawerOpen(Gravity.LEFT)
           || drawer.isDrawerOpen(Gravity.RIGHT));
 }
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
      if (!contentView.isDrawerOpen(browserListView)) contentView.openDrawer(browserListView);
      else contentView.closeDrawer(browserListView);
      return true;
    }
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
      // Finder is active, close it then
      if (bar.findViewById(R.id.finder) != null) {
        SetupLayouts.dismissFindBar();
        return true;
      } else {

        CustomWebView WV = (CustomWebView) webLayout.findViewById(R.id.browser_page);

        if (WV != null) {
          if (WV.canGoBack()) {
            if (!MainActivity.contentView.isDrawerOpen(MainActivity.browserListView)) WV.goBack();
            return true;
          }
        }
        if ((WV != null && WV.canGoBack() == false) || webWindows.size() == 0) {
          doExiting();
        }
      }
      return true;
    }
    return false;
  };
Beispiel #4
0
  public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
        // 如果ActionBar设置setDisplayHomeAsUpEnabled为true,则可以监听到前面的箭头图标
      case android.R.id.home:
        if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
          drawerLayout.closeDrawers();
        } else {
          drawerLayout.openDrawer(Gravity.LEFT);
        }
        break;
      case R.id.action_settings:
        startActivity(new Intent(this, SettingActivity.class));
        break;
      case R.id.action_about:
        startActivity(new Intent(this, AboutActivity.class));
        break;
      case R.id.action_share:
        startActivity(
            ShareActivity.makeIntent(
                this, "干货集中营", "每日分享妹子图 和 技术干货,还有供大家中午休息的休闲视频。", "http://gank.io"));
        break;
      default:
        break;
    }

    return super.onOptionsItemSelected(item);
  }
  @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);
        }
      }
    }
  }
 /** * Called when invalidateOptionsMenu() is triggered */
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   // if nav drawer is opened, hide the action items
   boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
   menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
   return super.onPrepareOptionsMenu(menu);
 }
 @Override
 public void onBackPressed() {
   if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
     drawerLayout.closeDrawers();
     return;
   } else {
     if (((BaseFragment) mStacks.get(mCurrentTab).lastElement()).onBackPressed() == false) {
       /*
        * top fragment in current tab doesn't handles back press, we can do our thing, which is
        *
        * if current tab has only one fragment in stack, ie first fragment is showing for this tab.
        *        finish the activity
        * else
        *        pop to previous fragment in stack for the same tab
        *
        */
       if (mStacks.get(mCurrentTab).size() == 1) {
         super.onBackPressed(); // or call finish..
       } else {
         popFragments();
       }
     } else {
       // do nothing.. fragment already handled back button press.
     }
   }
 }
  @Override
  public void onBackPressed() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
      mDrawer.closeDrawer(GravityCompat.START);
      return;
    }

    // handle back button for all fragment
    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.content_frame);
    if (fragment instanceof FavoriteBoardFragment) {
      if (!favoriteBoardFragment.atFavoriteRoot()) {
        favoriteBoardFragment.popFavoritePath();
        favoriteBoardFragment.RefreshFavoriteBoards();
        return;
      }
    }

    if (fragment != hotTopicFragment) {
      // return to hottopic if we are not there yet
      String title = "首页导读";
      FragmentManager fm = getSupportFragmentManager();
      fm.beginTransaction().replace(R.id.content_frame, hotTopicFragment).commit();
      setTitle(SMTHApplication.App_Title_Prefix + title);
      return;
    }

    // for other cases, double back to exit app
    DoubleBackToExit();
  }
Beispiel #9
0
 public void toggleDrawer() {
   if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
     drawerLayout.closeDrawer(GravityCompat.START);
   } else {
     drawerLayout.openDrawer(GravityCompat.START);
   }
 }
  @Override
  public void onBackPressed() {

    // Fragment f = getFragmentManager().findFragmentById(R.id.content_frame);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
      drawer.closeDrawer(GravityCompat.START);
    } else if (getFragmentManager().getBackStackEntryCount() > 0) {

      getFragmentManager().popBackStack();
      getFragmentManager().executePendingTransactions();
      Fragment f = getFragmentManager().findFragmentById(R.id.content_frame);
      int id = f.getArguments().getInt(FoodFragment.ARG_CAT_NUMBER);
      setPageTitle(id);

      // Fragment f = getFragmentManager().findFragmentById(R.id.content_frame);
      // int id = f.getArguments().getInt(FoodFragment.ARG_CAT_NUMBER);
      // setPageTitle(id);
      Log.w("EatThruCollege", "popped from backstack");
      //   getSupportFragmentManager().executePendingTransactions();
    } else {
      Log.w("EatThruCollege", "did not add to backstack");
      super.onBackPressed();
    }
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.cart_add_by_voice:
       Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
       intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
       intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.cart_add_voice_prompt));
       intent.putExtra(
           RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
       intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
       startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
       break;
     case R.id.cart_add_by_barcode:
       IntentIntegrator integrator = new IntentIntegrator(this);
       integrator.initiateScan();
       break;
     case android.R.id.home:
       if (mDrawerLayout.isDrawerOpen(mDrawerList)) mDrawerLayout.closeDrawer(mDrawerList);
       else {
         // Specify the parent activity
         Intent parentActivityIntent = new Intent(this, ShopCartOverviewFragmentActivity.class);
         parentActivityIntent.addFlags(
             Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
         startActivity(parentActivityIntent);
         this.finish();
       }
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
Beispiel #12
0
 /**
  * checks if the drawer exists and is opened.
  *
  * @return <code>true</code> if the drawer is open, else <code>false</code>
  */
 public boolean isDrawerOpen() {
   if (mDrawerLayout != null) {
     return mDrawerLayout.isDrawerOpen(GravityCompat.START);
   } else {
     return false;
   }
 }
 private boolean isRootsDrawerOpen() {
   if (mShowAsDialog) {
     return false;
   } else {
     return mDrawerLayout.isDrawerOpen(mRootsDrawer);
   }
 }
 public void Drawer() {
   if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
     mDrawerLayout.closeDrawer(mDrawerList);
   } else {
     mDrawerLayout.openDrawer(mDrawerList);
   }
 }
 public void toggleDrawer() {
   if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
     mDrawerLayout.closeDrawer(Gravity.RIGHT);
   } else {
     mDrawerLayout.openDrawer(Gravity.RIGHT);
   }
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   // The action bar home/up action should open or close the drawer.
   // ActionBarDrawerToggle will take care of this.
   switch (item.getItemId()) {
     case android.R.id.home:
       if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
         mDrawerLayout.closeDrawer(mDrawerList);
       } else {
         mDrawerLayout.openDrawer(mDrawerList);
         SharedPreferences myPrefs = getSharedPreferences("myPrefs", MODE_PRIVATE);
         if (!myPrefs.contains("drawerFinished")) {
           myPrefs
               .edit()
               .putString("drawerFinished", "true")
               .commit(); // Open the drawer on first install of app only
         }
       }
       return true;
     case R.id.action_settings:
       Intent intent = new Intent(this, settingsActivity.class);
       startActivity(intent);
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
 /* Called whenever we call invalidateOptionsMenu() */
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   // If the nav drawer is open, hide action items related to the content view
   boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
   menu.findItem(R.id.action_search).setVisible(!drawerOpen);
   return super.onPrepareOptionsMenu(menu);
 }
Beispiel #18
0
  /* *
   * Called when invalidateOptionsMenu() is triggered
   */
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    // if nav drawer is opened, hide the action items
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    // if user not loggin, hide the action profile and logout
    boolean checkloggin = (session.isLoggedIn() && session != null);
    boolean checklogginFB = (sessionFacebook != null && sessionFacebook.isOpened());
    boolean check =
        (session != null && session.isLoggedIn())
            || (sessionFacebook != null && sessionFacebook.isOpened());
    menu.findItem(R.id.action_search).setVisible(!drawerOpen);
    menu.findItem(R.id.action_location_found).setVisible(!drawerOpen);
    menu.findItem(R.id.action_login).setVisible(!drawerOpen);
    menu.findItem(R.id.action_profile).setVisible(!drawerOpen);
    menu.findItem(R.id.action_logOut).setVisible(!drawerOpen);

    /*menu.findItem(R.id.action_profile).setVisible(checkloggin);
    menu.findItem(R.id.action_logOut).setVisible(checkloggin);
    menu.findItem(R.id.action_login).setVisible(!checkloggin);

    menu.findItem(R.id.action_logOut).setVisible(!checklogginFB);
    menu.findItem(R.id.action_profile).setVisible(!checklogginFB);
    menu.findItem(R.id.action_login).setVisible(checklogginFB);
      */
    // menu.findItem(R.id.action_profile).setVisible(check);
    menu.findItem(R.id.action_profile).setVisible(!checklogginFB);
    menu.findItem(R.id.action_profile).setVisible(checkloggin);
    menu.findItem(R.id.action_logOut).setVisible(check);
    menu.findItem(R.id.action_login).setVisible(!check);

    return super.onPrepareOptionsMenu(menu);
  }
Beispiel #19
0
 @Override
 public void onBackPressed() {
   DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
   String attachedFragment = fragmentManager.findFragmentById(R.id.container).getTag();
   if (drawer.isDrawerOpen(GravityCompat.START)) {
     drawer.closeDrawer(GravityCompat.START);
   } else {
     switch (attachedFragment) {
       case Constants.FRAGMENT_NOTE:
       case Constants.FRAGMENT_TRASH_NOTE:
         if (textToFind.length() == 0) attachFragment(Constants.FRAGMENT_LIST);
         else attachFragment(Constants.FRAGMENT_SEARCH);
         break;
       case Constants.FRAGMENT_SEARCH:
         attachFragment(Constants.FRAGMENT_LIST);
         break;
       case Constants.FRAGMENT_LIST:
         if (!exit) {
           exit = true;
           handler.postDelayed(exitRunnable, 5000);
           Utils.showToast(this, getString(R.string.press_back_button_again_to_exit));
         } else {
           // Exit flag reset and canceling exit runnable in onStop method to handle home button
           // presses
           super.onBackPressed();
         }
         break;
     }
   }
 }
Beispiel #20
0
 public void syncState() {
   if (mDrawerLayout.isDrawerOpen(0x800003)) {
     mSlider.setPosition(1.0F);
   } else {
     mSlider.setPosition(0.0F);
   }
   if (mDrawerIndicatorEnabled) {
     SlideDrawable slidedrawable = mSlider;
     int i;
     if (mDrawerLayout.isDrawerOpen(0x800003)) {
       i = mCloseDrawerContentDescRes;
     } else {
       i = mOpenDrawerContentDescRes;
     }
     setActionBarUpIndicator(slidedrawable, i);
   }
 }
Beispiel #21
0
 @Override
 public void onBackPressed() {
   if (drawerLayout.isDrawerOpen(Gravity.START)) {
     drawerLayout.closeDrawers();
     return;
   }
   super.onBackPressed();
 }
 @Override
 public void onBackPressed() {
   if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
     hideDrawer();
   } else {
     super.onBackPressed();
   }
 }
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);

    menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
    atualizarTitulo(drawerOpen);
    return super.onPrepareOptionsMenu(menu);
  }
Beispiel #24
0
 @Override
 public void onBackPressed() {
   if (drawerLayout.isDrawerOpen(drawer)) {
     drawerLayout.closeDrawer(drawer);
   } else {
     super.onBackPressed();
   }
 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   if (!drawerLayout.isDrawerOpen(GravityCompat.START)) {
     getMenuInflater().inflate(R.menu.menu_main, menu);
     return true;
   }
   return super.onCreateOptionsMenu(menu);
 }
 @Override
 public void onBackPressed() {
   if (mDrawerLayout.isDrawerOpen(mDrawerListView)) {
     mDrawerLayout.closeDrawer(mDrawerListView);
   } else {
     super.onBackPressed();
   }
 }
Beispiel #27
0
 @Override
 public void onBackPressed() {
   if (_drawer.isDrawerOpen(GravityCompat.START)) {
     _drawer.closeDrawer(GravityCompat.START);
   } else {
     super.onBackPressed();
   }
 }
 @OnClick(R.id.bar_logo)
 public void bar_logo() {
   if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
     mDrawerLayout.closeDrawer(GravityCompat.START);
   } else {
     mDrawerLayout.openDrawer(GravityCompat.START);
   }
 }
Beispiel #29
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    if (mMainActivityDrawerLayout.isDrawerOpen(mMainActivityNavigationView)) {
      menu.close();
    }

    return super.onPrepareOptionsMenu(menu);
  }
Beispiel #30
0
 @Override
 public void onBackPressed() {
   drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
   if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
     drawerLayout.closeDrawer(GravityCompat.START);
   } else {
     super.onBackPressed();
   }
 }