Esempio n. 1
0
  /** Used to control the user settings shown when registered. */
  private void updateUserControlMenuItems() {
    if (mService == null
        || mService.getCurrentUser() == null
        || userRegisterItem == null
        || userCommentItem == null
        || userInformationItem == null) return;

    boolean userRegistered = mService.getCurrentUser().isRegistered;
    userRegisterItem.setEnabled(!userRegistered);
    userCommentItem.setEnabled(userRegistered);
    userInformationItem.setEnabled(userRegistered);
  }
  @Override
  protected void createOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.chess_game_fragment, menu);
    final MenuItem castleMenuItem = menu.findItem(R.id.chess_game_fragment_menu_castle);

    if (board == null) {
      castleMenuItem.setEnabled(false);
    } else {
      if (((Board) board).canCastle()) {
        castleMenuItem.setEnabled(true);
      } else {
        castleMenuItem.setEnabled(false);
      }
    }
  }
Esempio n. 3
0
  @Override
  public void invalidateOptionsMenu() {
    super.invalidateOptionsMenu();

    if (applyItem != null)
      applyItem.setEnabled(adapter != null && !TextUtils.isEmpty(adapter.getCommentText()));
  }
 @Override
 public void onPrepareOptionsMenu(Menu menu) {
   if (classList == null || classList.size() == 0) {
     menu.findItem(R.id.map_all_classes).setEnabled(false);
     MenuItem exportSchedule;
     // <4.0 can't export schedule, so MenuItem will be null
     if ((exportSchedule = menu.findItem(R.id.export_schedule)) != null) {
       exportSchedule.setEnabled(false);
     }
   } else {
     menu.findItem(R.id.map_all_classes).setEnabled(true);
     MenuItem exportSchedule;
     if ((exportSchedule = menu.findItem(R.id.export_schedule)) != null) {
       exportSchedule.setEnabled(true);
     }
   }
 }
 private void setEvernoteMenuEnabled(MenuItem item) {
   if (item != null) {
     boolean loggedIn = false;
     if (session != null) {
       loggedIn = session.isLoggedIn();
     }
     item.setEnabled(loggedIn);
     item.setVisible(loggedIn);
   }
 }
 private void updateEnablement() {
   if (loginItem != null) loginItem.setEnabled(loginEnabled());
 }
Esempio n. 7
0
  /**
   * Hide menu items not appropriate for the current context.
   *
   * <p><strong>Note:</strong> Please adjust the comments in {@code
   * res/menu/message_list_option.xml} if you change the visibility of a menu item in this method.
   *
   * @param menu The {@link Menu} instance that should be modified. May be {@code null}; in that
   *     case the method does nothing and immediately returns.
   */
  private void configureMenu(Menu menu) {
    if (menu == null) {
      return;
    }

    // Set visibility of account/folder settings menu items
    if (mMessageListFragment == null) {
      menu.findItem(R.id.account_settings).setVisible(false);
      menu.findItem(R.id.folder_settings).setVisible(false);
    } else {
      menu.findItem(R.id.account_settings).setVisible(mMessageListFragment.isSingleAccountMode());
      menu.findItem(R.id.folder_settings).setVisible(mMessageListFragment.isSingleFolderMode());
    }

    /*
     * Set visibility of menu items related to the message view
     */

    if (mDisplayMode == DisplayMode.MESSAGE_LIST
        || mMessageViewFragment == null
        || !mMessageViewFragment.isInitialized()) {
      menu.findItem(R.id.next_message).setVisible(false);
      menu.findItem(R.id.previous_message).setVisible(false);
      menu.findItem(R.id.delete).setVisible(false);
      menu.findItem(R.id.single_message_options).setVisible(false);
      menu.findItem(R.id.refile).setVisible(false);
      menu.findItem(R.id.toggle_unread).setVisible(false);
      menu.findItem(R.id.select_text).setVisible(false);
      menu.findItem(R.id.toggle_message_view_theme).setVisible(false);
      menu.findItem(R.id.show_headers).setVisible(false);
      menu.findItem(R.id.hide_headers).setVisible(false);
    } else {
      // hide prev/next buttons in split mode
      if (mDisplayMode != DisplayMode.MESSAGE_VIEW) {
        menu.findItem(R.id.next_message).setVisible(false);
        menu.findItem(R.id.previous_message).setVisible(false);
      } else {
        MessageReference ref = mMessageViewFragment.getMessageReference();
        boolean initialized =
            (mMessageListFragment != null && mMessageListFragment.isLoadFinished());
        boolean canDoPrev = (initialized && !mMessageListFragment.isFirst(ref));
        boolean canDoNext = (initialized && !mMessageListFragment.isLast(ref));

        MenuItem prev = menu.findItem(R.id.previous_message);
        prev.setEnabled(canDoPrev);
        prev.getIcon().setAlpha(canDoPrev ? 255 : 127);

        MenuItem next = menu.findItem(R.id.next_message);
        next.setEnabled(canDoNext);
        next.getIcon().setAlpha(canDoNext ? 255 : 127);
      }

      MenuItem toggleTheme = menu.findItem(R.id.toggle_message_view_theme);
      if (K9.useFixedMessageViewTheme()) {
        toggleTheme.setVisible(false);
      } else {
        // Set title of menu item to switch to dark/light theme
        if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
          toggleTheme.setTitle(R.string.message_view_theme_action_light);
        } else {
          toggleTheme.setTitle(R.string.message_view_theme_action_dark);
        }
        toggleTheme.setVisible(true);
      }

      // Set title of menu item to toggle the read state of the currently displayed message
      if (mMessageViewFragment.isMessageRead()) {
        menu.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_unread_action);
      } else {
        menu.findItem(R.id.toggle_unread).setTitle(R.string.mark_as_read_action);
      }

      menu.findItem(R.id.copy).setVisible(mMessageViewFragment.isCopyCapable());

      // Jellybean has built-in long press selection support
      menu.findItem(R.id.select_text).setVisible(Build.VERSION.SDK_INT < 16);

      if (mMessageViewFragment.isMoveCapable()) {
        menu.findItem(R.id.move).setVisible(true);
        menu.findItem(R.id.archive).setVisible(mMessageViewFragment.canMessageBeArchived());
        menu.findItem(R.id.spam).setVisible(mMessageViewFragment.canMessageBeMovedToSpam());
      } else {
        menu.findItem(R.id.move).setVisible(false);
        menu.findItem(R.id.archive).setVisible(false);
        menu.findItem(R.id.spam).setVisible(false);
      }

      if (mMessageViewFragment.allHeadersVisible()) {
        menu.findItem(R.id.show_headers).setVisible(false);
      } else {
        menu.findItem(R.id.hide_headers).setVisible(false);
      }
    }

    /*
     * Set visibility of menu items related to the message list
     */

    // Hide both search menu items by default and enable one when appropriate
    menu.findItem(R.id.search).setVisible(false);
    menu.findItem(R.id.search_remote).setVisible(false);

    if (mDisplayMode == DisplayMode.MESSAGE_VIEW
        || mMessageListFragment == null
        || !mMessageListFragment.isInitialized()) {
      menu.findItem(R.id.check_mail).setVisible(false);
      menu.findItem(R.id.set_sort).setVisible(false);
      menu.findItem(R.id.select_all).setVisible(false);
      menu.findItem(R.id.send_messages).setVisible(false);
      menu.findItem(R.id.expunge).setVisible(false);
    } else {
      menu.findItem(R.id.set_sort).setVisible(true);
      menu.findItem(R.id.select_all).setVisible(true);

      if (!mMessageListFragment.isSingleAccountMode()) {
        menu.findItem(R.id.expunge).setVisible(false);
        menu.findItem(R.id.check_mail).setVisible(false);
        menu.findItem(R.id.send_messages).setVisible(false);
      } else {
        menu.findItem(R.id.send_messages).setVisible(mMessageListFragment.isOutbox());

        if (mMessageListFragment.isRemoteFolder()) {
          menu.findItem(R.id.check_mail).setVisible(true);
          menu.findItem(R.id.expunge).setVisible(mMessageListFragment.isAccountExpungeCapable());
        } else {
          menu.findItem(R.id.check_mail).setVisible(false);
          menu.findItem(R.id.expunge).setVisible(false);
        }
      }

      // If this is an explicit local search, show the option to search on the server
      if (!mMessageListFragment.isRemoteSearch() && mMessageListFragment.isRemoteSearchAllowed()) {
        menu.findItem(R.id.search_remote).setVisible(true);
      } else if (!mMessageListFragment.isManualSearch()) {
        menu.findItem(R.id.search).setVisible(true);
      }
    }
  }