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.cerema.cloud2.ui.preview.PreviewTextFragment.java

/**
 * {@inheritDoc}/*from   ww  w  .  j a v  a  2s  .  c  o m*/
 */
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    if (mContainerActivity.getStorageManager() != null) {
        FileMenuFilter mf = new FileMenuFilter(getFile(), mContainerActivity.getStorageManager().getAccount(),
                mContainerActivity, getActivity());
        mf.filter(menu);
    }

    // additional restriction for this fragment
    MenuItem item = menu.findItem(R.id.action_rename_file);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    // additional restriction for this fragment
    item = menu.findItem(R.id.action_move);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    // this one doesn't make sense since the file has to be down in order to be previewed
    item = menu.findItem(R.id.action_download_file);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    item = menu.findItem(R.id.action_sync_file);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    item = menu.findItem(R.id.action_sync_account);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    Boolean dualPane = getResources().getBoolean(R.bool.large_land_layout);

    item = menu.findItem(R.id.action_switch_view);
    if (item != null && !dualPane) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    item = menu.findItem(R.id.action_sort);
    if (item != null && !dualPane) {
        item.setVisible(false);
        item.setEnabled(false);
    }
}

From source file:net.reichholf.dreamdroid.activities.ServiceListActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem overview = menu.getItem(2);

    if (mReference.equals("default")) {
        overview.setEnabled(false);
    } else {/*from w w  w. jav a 2  s  .  co  m*/
        overview.setEnabled(true);
    }

    MenuItem reload = menu.getItem(1);
    if (!mIsBouquetList && !mPickMode) {
        reload.setEnabled(true);
    } else {
        reload.setEnabled(false);
    }
    return true;
}

From source file:org.thaliproject.nativetest.app.fragments.PeerListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.menu_peers, menu);

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    int position = info.position;
    PeerProperties peerProperties = (PeerProperties) mListView.getItemAtPosition(position);

    MenuUtils.PeerMenuItemsAvailability availability = MenuUtils
            .resolvePeerMenuItemsAvailability(peerProperties, mModel);

    MenuItem connectMenuItem = menu.getItem(0);
    MenuItem disconnectMenuItem = menu.getItem(1);
    MenuItem sendDataMenuItem = menu.getItem(2);

    connectMenuItem.setEnabled(availability.connectMenuItemAvailable);
    sendDataMenuItem.setEnabled(availability.sendDataMenuItemAvailable);
    disconnectMenuItem.setEnabled(availability.disconnectMenuItemAvailable);
}

From source file:ca.rmen.android.poetassistant.main.reader.ReaderFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    boolean hasEnteredText = !TextUtils.isEmpty(mBinding.tvText.getText());
    MenuItem menuItem = menu.findItem(R.id.action_new);
    if (menuItem == null) {
        Log.d(TAG, "Unexpected: new menu item missing from reader fragment. Monkey?");
    } else {//from   w  w  w.  ja v  a2 s . c  o m
        menuItem.setEnabled(hasEnteredText);
    }

    menuItem = menu.findItem(R.id.action_save);
    if (menuItem == null) {
        Log.d(TAG, "Unexpected: save menu item missing from reader fragment. Monkey?");
    } else {
        menuItem.setEnabled(mPoemPrefs.hasSavedPoem());
    }

    menuItem = menu.findItem(R.id.action_save_as);
    if (menuItem == null) {
        Log.d(TAG, "Unexpected: save as menu item missing from reader fragment. Monkey?");
    } else {
        menuItem.setEnabled(hasEnteredText);
    }
}

From source file:app.CT.BTCCalculator.fragments.BreakevenFragment.java

private void enableMenuItems() {
    MenuItem buy = menu.findItem(R.id.editCurrentBuyField);
    MenuItem sell = menu.findItem(R.id.editCurrentSellField);
    MenuItem reset = menu.findItem(R.id.resetAll);

    if (!buy.isEnabled())
        buy.setEnabled(true);
    if (!sell.isEnabled())
        sell.setEnabled(true);//from   ww  w .j ava 2 s  .  c o m
    if (!reset.isEnabled())
        reset.setEnabled(true);
}

From source file:org.hfoss.posit.android.RegisterActivity.java

/**
 * Creates the menu options for the PositMain screen. Menu items are
 * inflated from a resource file.//from   w w  w .  java2s  . c o  m
 * 
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.positmain_menu, menu);
    MenuItem item = menu.findItem(R.id.projects_menu_item);
    item.setEnabled(false);
    item = menu.findItem(R.id.track_menu_item);
    item.setEnabled(false);
    return true;
}

From source file:org.geometerplus.android.fbreader.network.NetworkLibraryActivity.java

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

    final NetworkTree tree = getCurrentTree();
    for (Action a : myOptionsMenuActions) {
        final MenuItem item = menu.findItem(a.Code);
        if (a.isVisible(tree)) {
            item.setVisible(true);// w ww  .  j  a va 2  s  . c o  m
            item.setEnabled(a.isEnabled(tree));
            item.setTitle(a.getOptionsLabel(tree));
        } else {
            item.setVisible(false);
        }
    }
    return true;
}

From source file:co.carlosandresjimenez.android.gotit.RegistrationFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.

    int id = item.getItemId();
    if (id == R.id.action_save) {
        saveUserDetails();//from  w  ww . j  av  a 2s  . co m
        item.setEnabled(false);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.zion.htf.ui.fragment.ArtistDetailsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.artist_details, menu);

    if (0 == this.setId) {
        MenuItem addAlarmMenuItem = menu.findItem(R.id.action_addAlarm);
        MenuItem editAlarmMenuItem = menu.findItem(R.id.action_editAlarm);
        if (null != addAlarmMenuItem) {
            addAlarmMenuItem.setVisible(false);
            addAlarmMenuItem.setEnabled(false);
        }//from w  w w.j a va 2  s.  c o m
        if (null != editAlarmMenuItem) {
            editAlarmMenuItem.setVisible(false);
            editAlarmMenuItem.setEnabled(false);
        }
    }
}

From source file:com.github.kanata3249.ffxieq.android.AugmentSelectorActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.augmentselector_context, menu);

    MenuItem item = menu.findItem(R.id.DeleteAugment);
    if (item != null) {
        item.setEnabled(mLongClickingItemId != mAugID);
    }//from  w  w  w. ja va 2 s.  c om
}