Example usage for android.view MenuItem setEnabled

List of usage examples for android.view MenuItem setEnabled

Introduction

In this page you can find the example usage for android.view MenuItem setEnabled.

Prototype

public MenuItem setEnabled(boolean enabled);

Source Link

Document

Sets whether the menu item is enabled.

Usage

From source file:com.concentricsky.android.khanacademy.app.VideoDetailActivity.java

private void prepareDownloadActionItem(MenuItem item, int downloadPercent) {
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    int dlRes = R.drawable.av_download;
    int removeRes = R.drawable.content_discard;

    switch (downloadPercent) {
    case PARAM_PROGRESS_DONE:
        videoIsDownloaded = true;/*from w  w  w .j a va 2s.co  m*/
        item.setEnabled(true).setTitle("Downloaded").setIcon(getResources().getDrawable(removeRes));
        break;
    case PARAM_PROGRESS_UNKNOWN:
        if (video != null) {
            try {
                dataService.getHelper().getVideoDao().refresh(video);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            switch (video.getDownload_status()) {
            case Video.DL_STATUS_COMPLETE:
                videoIsDownloaded = true;
                item.setEnabled(true).setTitle("Downloaded").setIcon(getResources().getDrawable(removeRes));
                break;
            case Video.DL_STATUS_IN_PROGRESS:
                videoIsDownloaded = false;
                item.setEnabled(false).setTitle("Downloading").setIcon(getResources().getDrawable(dlRes));
                break;
            case Video.DL_STATUS_NOT_STARTED:
            default:
                videoIsDownloaded = false;
                item.setEnabled(true).setTitle("Download").setIcon(getResources().getDrawable(dlRes));
            }
        }
        break;
    default:
        videoIsDownloaded = false;
        item.setEnabled(false).setTitle(downloadPercent + "%").setIcon(null);
    }
}

From source file:dev.memento.MementoBrowser.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    // Only enable the "List" menu if there are Memento dates to display
    MenuItem item = menu.findItem(R.id.menu_list);
    item.setEnabled(mMementos.size() != 0);

    // Only enable "Return to Present" if we are not viewing the present
    item = menu.findItem(R.id.menu_off);
    item.setEnabled(!mToday.equalsDate(mDateChosen));

    return true;//from  w ww  .j  a  va  2  s  .  co m
}

From source file:uk.co.pjmobile.mobile_apps.page_turner_reader.ReadingActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    //      if (this.tocDialog == null) {
    //         initTocDialog();
    //      }/*ww w  .  j a  va2s .  c  o  m*/

    MenuItem nightMode = menu.findItem(R.id.profile_night);
    MenuItem dayMode = menu.findItem(R.id.profile_day);

    MenuItem showToc = menu.findItem(R.id.show_toc);
    //      MenuItem sync = menu.findItem(R.id.manual_sync);

    showToc.setEnabled(true);
    //      sync.setEnabled(config.isSyncEnabled());

    if (config.getColourProfile() == ColourProfile.DAY) {
        dayMode.setVisible(false);
        nightMode.setVisible(true);
    } else {
        dayMode.setVisible(true);
        nightMode.setVisible(false);
    }

    // Only show open file item if we have a file manager installed
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("file/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    if (!isIntentAvailable(this, intent)) {
        //         menu.findItem(R.id.open_file).setVisible(false);
    }

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.vuze.android.remote.fragment.FilesFragment.java

protected boolean prepareContextMenu(Menu menu) {
    if (sessionInfo == null || torrentID < 0) {
        return false;
    }/*  w ww.  ja  va  2 s  .  c  o m*/

    boolean isComplete = false;
    Map<?, ?> mapFile = getFocusedFile();
    boolean enable = mapFile != null && mapFile.size() > 0;
    if (mapFile != null) {
        long bytesCompleted = MapUtils.getMapLong(mapFile, "bytesCompleted", 0);
        long length = MapUtils.getMapLong(mapFile, "length", -1);
        //System.out.println("mapFIle=" + mapFile);
        isComplete = bytesCompleted == length;
    }

    boolean isLocalHost = sessionInfo != null && sessionInfo.getRemoteProfile().isLocalHost();
    boolean isOnlineOrLocal = VuzeRemoteApp.getNetworkState().isOnline() || isLocalHost;

    MenuItem menuLaunch = menu.findItem(R.id.action_sel_launch);
    if (menuLaunch != null) {
        if (enable && sessionInfo.getRemoteProfile().isLocalHost()) {
            boolean canLaunch = isComplete;
            canLaunch &= isOnlineOrLocal;
            menuLaunch.setEnabled(canLaunch);
            menuLaunch.setVisible(true);
        } else {
            menuLaunch.setVisible(false);
        }
    }

    MenuItem menuLaunchStream = menu.findItem(R.id.action_sel_launch_stream);
    if (menuLaunchStream != null) {
        boolean canStream = enable && isComplete
                && mapFile.containsKey(TransmissionVars.FIELD_FILES_CONTENT_URL);
        canStream &= isOnlineOrLocal;
        menuLaunchStream.setEnabled(canStream);
    }

    MenuItem menuSave = menu.findItem(R.id.action_sel_save);
    if (menuSave != null) {
        boolean visible = !isLocalHost;
        menuSave.setVisible(visible);
        if (visible) {
            boolean canSave = enable && isOnlineOrLocal && isComplete
                    && mapFile.containsKey(TransmissionVars.FIELD_FILES_CONTENT_URL);
            menuSave.setEnabled(canSave);
        }
    }

    int priority = MapUtils.getMapInt(mapFile, TransmissionVars.FIELD_TORRENT_FILES_PRIORITY,
            TransmissionVars.TR_PRI_NORMAL);
    MenuItem menuPriorityUp = menu.findItem(R.id.action_sel_priority_up);
    if (menuPriorityUp != null) {
        menuPriorityUp.setEnabled(
                enable && isOnlineOrLocal && !isComplete && priority < TransmissionVars.TR_PRI_HIGH);
    }
    MenuItem menuPriorityDown = menu.findItem(R.id.action_sel_priority_down);
    if (menuPriorityDown != null) {
        menuPriorityDown
                .setEnabled(enable && isOnlineOrLocal && !isComplete && priority > TransmissionVars.TR_PRI_LOW);
    }

    boolean wanted = MapUtils.getMapBoolean(mapFile, "wanted", true);
    MenuItem menuUnwant = menu.findItem(R.id.action_sel_unwanted);
    if (menuUnwant != null) {
        menuUnwant.setVisible(wanted);
        menuUnwant.setEnabled(enable && isOnlineOrLocal);
    }
    MenuItem menuWant = menu.findItem(R.id.action_sel_wanted);
    if (menuWant != null) {
        menuWant.setVisible(!wanted);
        menuWant.setEnabled(enable && isOnlineOrLocal);
    }

    AndroidUtils.fixupMenuAlpha(menu);
    return true;
}

From source file:app.sunstreak.yourpisd.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_activity, menu);

    // Create list of students in Menu.
    if (session.MULTIPLE_STUDENTS) {
        for (int i = 0; i < session.getStudents().size(); i++) {
            String name = session.getStudents().get(i).name;
            MenuItem item = menu.add(name);

            // Set the currently enabled student un-clickable.
            if (i == session.studentIndex)
                item.setEnabled(false);

            item.setOnMenuItemClickListener(new StudentChooserListener(i));
            item.setVisible(true);/*from ww w.  ja  v a2 s . c  om*/
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:org.hopestarter.wallet.ui.send.SendCoinsFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    final MenuItem scanAction = menu.findItem(R.id.send_coins_options_scan);
    final PackageManager pm = activity.getPackageManager();
    scanAction.setVisible(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
            || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));
    scanAction.setEnabled(state == State.INPUT);

    super.onPrepareOptionsMenu(menu);
}

From source file:org.opendatakit.tables.activities.TableDisplayActivity.java

/**
 * Disable or enable those menu items corresponding to view types that are
 * currently invalid or valid, respectively. The inflatedMenu must have
 * already been created from the resource.
 * /*from  w w w  .j a  v  a2 s  .c o m*/
 * @param validViewTypes
 * @param inflatedMenu
 */
private void enableAndDisableViewTypes(PossibleTableViewTypes possibleViews, Menu inflatedMenu) {
    MenuItem spreadsheetItem = inflatedMenu.findItem(R.id.top_level_table_menu_view_spreadsheet_view);
    MenuItem listItem = inflatedMenu.findItem(R.id.top_level_table_menu_view_list_view);
    MenuItem mapItem = inflatedMenu.findItem(R.id.top_level_table_menu_view_map_view);

    spreadsheetItem.setEnabled(possibleViews.spreadsheetViewIsPossible());
    listItem.setEnabled(possibleViews.listViewIsPossible());
    mapItem.setEnabled(possibleViews.mapViewIsPossible());

}

From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java

private void setCommonMenu(final Menu menu) {
    final boolean hasMedia = hasMedia();
    final int activatedColor = getUserThemeColor(this);
    final MenuItem itemAddImageSubmenu = menu.findItem(R.id.add_image_submenu);
    if (itemAddImageSubmenu != null) {
        final Drawable iconAddImage = itemAddImageSubmenu.getIcon();
        iconAddImage.mutate();// www  . j a  v a  2 s .c om
        if (hasMedia) {
            iconAddImage.setColorFilter(activatedColor, Mode.SRC_ATOP);
        } else {
            iconAddImage.clearColorFilter();
        }
    }
    final MenuItem itemAttachLocation = menu.findItem(MENU_ADD_LOCATION);
    if (itemAttachLocation != null) {
        final Drawable iconAttachLocation = itemAttachLocation.getIcon().mutate();
        final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION, false);
        if (attachLocation && getLocation()) {
            iconAttachLocation.setColorFilter(activatedColor, Mode.SRC_ATOP);
            itemAttachLocation.setTitle(R.string.remove_location);
            itemAttachLocation.setChecked(true);
        } else {
            setProgressVisibility(false);
            mPreferences.edit().putBoolean(KEY_ATTACH_LOCATION, false).commit();
            iconAttachLocation.clearColorFilter();
            itemAttachLocation.setTitle(R.string.add_location);
            itemAttachLocation.setChecked(false);
        }
    }
    final MenuItem viewItem = menu.findItem(MENU_VIEW);
    if (viewItem != null) {
        viewItem.setVisible(mInReplyToStatus != null);
    }
    final MenuItem itemToggleSensitive = menu.findItem(MENU_TOGGLE_SENSITIVE);
    if (itemToggleSensitive != null) {
        itemToggleSensitive.setVisible(hasMedia);
        itemToggleSensitive.setEnabled(hasMedia);
        itemToggleSensitive.setChecked(hasMedia && mIsPossiblySensitive);
        if (hasMedia) {
            final Drawable iconToggleSensitive = itemToggleSensitive.getIcon().mutate();
            if (mIsPossiblySensitive) {
                itemToggleSensitive.setTitle(R.string.remove_sensitive_mark);
                iconToggleSensitive.setColorFilter(activatedColor, Mode.SRC_ATOP);
            } else {
                itemToggleSensitive.setTitle(R.string.mark_as_sensitive);
                iconToggleSensitive.clearColorFilter();
            }
        }
    }
}

From source file:cz.muni.fi.japanesedictionary.main.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);

    MenuItem noteItem = menu.findItem(R.id.ab_note);
    MenuItem favoriteItem = menu.findItem(R.id.favorite);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        searchItem.setVisible(!drawerOpen);
    }//from  ww w  .java2s . com

    if (drawerOpen) {
        //is open
        Log.i(LOG_TAG, "Drawer open");
        mNoteVisible = noteItem != null && noteItem.isVisible();
        mFavoriteVisible = favoriteItem != null && favoriteItem.isVisible();
        mSearchVisible = MenuItemCompat.isActionViewExpanded(searchItem);
        if (noteItem != null) {
            noteItem.setVisible(false);
        }
        if (favoriteItem != null) {
            favoriteItem.setVisible(false);
        }
        Log.i(LOG_TAG, "Drawer open - hide search");
        MenuItemCompat.collapseActionView(searchItem);
        if (searchItem != null) {
            searchItem.setVisible(false);
            searchItem.setEnabled(false);
        }

    } else {
        Log.i(LOG_TAG, "Drawer close");
        if (favoriteItem != null) {
            favoriteItem.setVisible(mFavoriteVisible);
        }
        if (noteItem != null) {
            noteItem.setVisible(mNoteVisible);
        }
        if (searchItem != null) {
            searchItem.setVisible(true);
            searchItem.setEnabled(true);
        }
        if (mSearchVisible) {
            Log.i(LOG_TAG, "Drawer close, expand search");
            MenuItemCompat.expandActionView(searchItem);
            mSearchView.setQuery(mCurFilter, false);
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:androidVNC.VncCanvasActivity.java

/**
 * Change the input mode sub-menu to reflect change in scaling
 *///from   w  ww  .j  ava 2  s  .  c  o  m
void updateInputMenu() {
    if (inputModeMenuItems == null || vncCanvas.scaling == null) {
        return;
    }
    for (MenuItem item : inputModeMenuItems) {
        item.setEnabled(vncCanvas.scaling.isValidInputMode(item.getItemId()));
        if (getInputHandlerById(item.getItemId()) == inputHandler)
            item.setChecked(true);
    }
}