Example usage for android.view MenuItem getTitle

List of usage examples for android.view MenuItem getTitle

Introduction

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

Prototype

public CharSequence getTitle();

Source Link

Document

Retrieve the current title of the item.

Usage

From source file:com.jins_meme.bridge.MainActivity.java

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

    //debug Log.d("DEBUG", "onPrepareOptionsMenu");

    String barTitle;//from ww w  . j  av a  2s.c  o m
    if (getSupportActionBar() != null && getSupportActionBar().getTitle() != null) {
        barTitle = getSupportActionBar().getTitle().toString();

        Log.d("DEBUG", "Title = " + barTitle);

        if (barTitle.length() > 1) {
            for (int i = 0; i < menu.size(); i++) {
                MenuItem item = menu.getItem(i);
                String title = item.getTitle().toString();

                if (title.contains(" (for Eye VDJ)")) {
                    title = title.substring(0, title.indexOf(" (for Eye VDJ)"));
                }

                if (barTitle.contains(title)) {
                    item.setVisible(false);
                } else {
                    item.setVisible(true);
                }
            }
        } else {
            for (int i = 0; i < menu.size(); i++) {
                menu.getItem(i).setVisible(true);
            }
        }
    }

    return true;
}

From source file:com.openatk.rockapp.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    if (mCurrentState == STATE_DEFAULT) {
        menu.clear();/* w w w .j a  v a2  s .c  o m*/
        inflater.inflate(R.menu.main, menu);

        MenuItem showHideItem = menu.findItem(R.id.show_hide);
        MenuItem currentShowHideItem;

        switch (mRockState) {
        case STATE_ROCKS_BOTH:
            currentShowHideItem = menu.findItem(R.id.all_rocks);
            break;

        case STATE_ROCKS_NOT_PICKED_UP:
            currentShowHideItem = menu.findItem(R.id.not_picked_rocks);
            break;

        case STATE_ROCKS_PICKED_UP:
            currentShowHideItem = menu.findItem(R.id.picked_rocks);
            break;
        default:
            // We are some how lost, just revert back to showing everything
            Log.e("MainActivity", "Lost Rock Shown State");
            mRockState = STATE_ROCKS_BOTH;
            currentShowHideItem = menu.findItem(R.id.all_rocks);
            break;
        }

        // Copy the current selection to the action bar
        showHideItem.setTitle(currentShowHideItem.getTitle());

        // Mark the current one as checked
        currentShowHideItem.setChecked(true);

        // The location button changes depending the current state
        // of location

        // TODO
        /*
         * MenuItem gps = menu.findItem(R.id.gps); if(map.ha) {
         * if(mRockLocationManager.haveUserLocation()) {
         * gps.setIcon(R.drawable.gps_found);
         * gps.setTitle(R.string.menu_gps); } else {
         * gps.setIcon(R.drawable.gps_searching);
         * gps.setTitle(R.string.menu_gps_searching); } } else {
         * gps.setIcon(R.drawable.gps_off);
         * gps.setTitle(R.string.menu_gps_off); }
         */
    } else if (mCurrentState == STATE_ROCK_EDIT) {
        menu.clear();
        inflater.inflate(R.menu.rock_edit_menu, menu);
        MenuItem undoButton = menu.findItem(R.id.rock_undo_move);
        if (undoMoves.isEmpty()) {
            undoButton.setVisible(false);
        } else {
            undoButton.setVisible(true);
        }
    }
    return true;
}

From source file:com.jins_meme.bridge.MainActivity.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    CharSequence cs = item.getTitle();

    if (cs == null) {
        Log.d("DEBUG", "press actionbar back!");
        return true;
    }/*from  w w w  .ja  v a 2s .c  om*/

    String itemTitle = item.getTitle().toString();

    Log.d("DEBUG", "item id = " + item.getItemId() + " " + itemTitle);

    if (itemTitle.equals(getString(R.string.basic_conf))) {
        Log.d("DEBUG", "tap basic setting");

        transitToFragment(basicConfigFragment);

        return true;
    } else if (itemTitle.equals(getString(R.string.spotify_conf))) {
        Log.d("DEBUG", "tap spotify setting");

        transitToFragment(spotifyConfigFragment);

        return true;
    } else if (itemTitle.equals(getString(R.string.hue_conf))) {
        Log.d("DEBUG", "tap hue setting");

        transitToFragment(hueConfigFragment);

        return true;
    } else if (itemTitle.equals(getString(R.string.remo_conf))) {
        Log.d("DEBUG", "tap remo setting");

        transitToFragment(remoConfigFragment);

        return true;
    } else if (itemTitle.contains(getString(R.string.osc_conf))) {
        Log.d("DEBUG", "tap osc setting");

        transitToFragment(oscConfigFragment);

        return true;
    } else if (itemTitle.contains(getString(R.string.midi_conf))) {
        Log.d("DEBUG", "tap midi setting");

        transitToFragment(midiConfigFragment);

        return true;
    }
    /*
     * MODIFY YOURSELF
     * Add your implemented function's configuration
     *
     */
    /*
    else if (itemTitle.equals(getString(R.string.***_config) {
      Log.d("DEBUG", "tap *** setting");
            
      transittToConfig(***ConfigFragment);
            
      return true;
    }
     */
    else if (itemTitle.equals(getString(R.string.about))) {
        Log.d("DEBUG", "tap about");

        transitToFragment(aboutFragment);

        return true;
    } else if (itemTitle.equals(getString(R.string.exit_app))) {
        finishAndRemoveTask();
    }

    return super.onOptionsItemSelected(item);
}

From source file:ufms.br.com.ufmsapp.activity.MainActivity.java

public void selectOptionsMenu(MenuItem menuItem) {
    mSelectedPosition = menuItem.getItemId();

    Fragment fragment;/*from  w  w  w  . jav  a 2 s . c  om*/

    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();

    switch (mSelectedPosition) {
    case R.id.nav_drawer_explore:
        fragment = ExploreFragment.newInstance();
        fragmentTransaction.replace(R.id.main_layout_container, fragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_drawer_eventos:
        fragment = EventosFragment.newInstance();
        fragmentTransaction.replace(R.id.main_layout_container, fragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_drawer_disciplina:
        fragment = DisciplinasFragment.newInstance();
        fragmentTransaction.replace(R.id.main_layout_container, fragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_drawer_notas:
        fragment = NotasFragment.newInstance();
        fragmentTransaction.replace(R.id.main_layout_container, fragment);
        fragmentTransaction.commit();
        break;
    case R.id.nav_drawer_curso:
        startActivity(new Intent(this, CursoActivity.class));
        break;

    case R.id.nav_drawer_config:
        startActivity(new Intent(this, SettingsActivity.class));
        break;

    }

    menuItem.setChecked(true);
    setTitle(menuItem.getTitle());

    if (isSmartphone()) {
        mDrawerLayout.closeDrawer(GravityCompat.START);
    }
}

From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java

/**
 * Method that show a new dialog for input a name.
 *
 * @param menuItem The item menu associated
 *///from  ww  w .j  a  v  a  2s. co m
private void showInputNameDialog(final MenuItem menuItem) {

    //Show the input name dialog
    final InputNameDialog inputNameDialog = new InputNameDialog(this,
            getCurrentNavigationFragment().onRequestCurrentItems(), menuItem.getTitle().toString());
    inputNameDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            //Retrieve the name an execute the action
            try {
                String name = inputNameDialog.getName();
                createNewFileSystemObject(menuItem.getItemId(), name);

            } catch (InflateException e) {
                //TODO handle this exception properly
            }
        }
    });
    inputNameDialog.show();
}

From source file:com.audiokernel.euphonyrmt.fragments.BrowseFragment.java

@Override
public boolean onMenuItemClick(final MenuItem item) {
    switch (item.getGroupId()) {
    case ADD_REPLACE_PLAY:
    case ADD_REPLACE:
    case ADD:// w  w w .j  av a 2s  .  c om
    case ADD_PLAY:
        addAndReplace(item);
        break;
    case ADD_TO_PLAYLIST:
        addToPlaylist(item);
        break;
    case GOTO_ARTIST:
        final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        final Object selectedItem = mItems.get((int) info.id);
        final Intent intent = new Intent(getActivity(), SimpleLibraryActivity.class);
        Artist artist = null;

        if (selectedItem instanceof Album) {
            artist = ((AbstractAlbum) selectedItem).getArtist();
        } else if (selectedItem instanceof Artist) {
            artist = (Artist) selectedItem;
        } else if (selectedItem instanceof Music) {
            artist = new Artist(((AbstractMusic) selectedItem).getAlbumArtistOrArtist());
        }

        if (artist != null) {
            intent.putExtra("artist", artist);
            startActivityForResult(intent, -1);
        }
        break;
    default:
        final String name = item.getTitle().toString();
        final int id = item.getOrder();
        mApp.oMPDAsyncHelper.execAsync(new Runnable() {
            @Override
            public void run() {
                add(mItems.get(id), name);
            }
        });
        break;
    }
    return false;
}

From source file:com.alchemiasoft.book.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override//from www . ja  v  a 2  s  . com
        public boolean onMenuItemClick(MenuItem menuItem) {
            final FragmentManager fm = getSupportFragmentManager();
            switch (menuItem.getItemId()) {
            case R.id.action_all_books:
                if (fm.findFragmentByTag(TAG_ALL_BOOKS) == null) {
                    getSupportFragmentManager().beginTransaction().replace(R.id.content,
                            BooksFragment.create(HomeActivity.this, false), TAG_ALL_BOOKS).commit();
                } else {
                    Log.d(TAG_LOG, "All books fragment is already attached.");
                }
                return true;
            case R.id.action_my_books:
                if (fm.findFragmentByTag(TAG_OWNED_BOOKS) == null) {
                    getSupportFragmentManager().beginTransaction().replace(R.id.content,
                            BooksFragment.create(HomeActivity.this, true), TAG_OWNED_BOOKS).commit();
                } else {
                    Log.d(TAG_LOG, "Owned books fragment is already attached.");
                }
                return true;
            case R.id.action_settings:
                Toast.makeText(HomeActivity.this, getString(R.string.not_implemented), Toast.LENGTH_SHORT)
                        .show();
                return true;
            case R.id.action_suggestion:
                // Scheduling a suggestion
                SuggestionReceiver.scheduleSuggestion(HomeActivity.this);
                return true;
            default:
                Log.w(TAG_LOG, "MenuItem: title=" + menuItem.getTitle() + " & itemId=" + menuItem.getItemId()
                        + " is not handled.");
                return false;
            }
        }
    });
    toolbar.inflateMenu(R.menu.menu_home);
    // Checking if first instance and then attach the first fragment
    if (savedInstanceState == null) {
        attachBookFragment(getIntent().getLongExtra(KEY_BOOK_ID, NOT_VALID));
    }
}

From source file:com.dsdar.thosearoundme.TeamViewActivity.java

/**
 * Method to get users team information and design action bar accordingly
 *///from ww w. jav  a 2  s  .c  o m

@Override
public boolean onCreateOptionsMenu(Menu theMenu) {

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

    MenuItem myItem = theMenu.findItem(R.id.invitations);
    MenuItem team = theMenu.findItem(R.id.myTeams);
    int invite_cnt = 0;
    if (MyAppConstants.INVITATION_CNT == -1) {
        invite_cnt = 0;
    } else {
        invite_cnt = MyAppConstants.INVITATION_CNT;
    }

    myItem.setTitle(myItem.getTitle() + "(" + invite_cnt + ")");
    if (intSupported == 0) {
        itsAddTeam.setVisibility(View.INVISIBLE);
        team.setVisible(false);
    } else {
        itsAddTeam.setVisibility(View.VISIBLE);
        team.setVisible(true);
    }
    // MenuItem myItem1 = theMenu.findItem(R.id.myFollowers);
    // myItem1.setTitle(myItem1.getTitle() + "("
    // + MyAppConstants.FOLLOWERS_CNT + ")");
    // TextView txtInviteCnt = (TextView) findViewById(R.id.invitations);
    // txtInviteCnt.setText("(" + MyAppConstants.INVITATION_CNT + ")");
    //
    // TextView txtFolowersCnt = (TextView) findViewById(R.id.myFollowers);
    // txtFolowersCnt.setText("(" + MyAppConstants.FOLLOWERS_CNT + ")");

    return super.onCreateOptionsMenu(theMenu);
}

From source file:de.sindzinski.wetter.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from   ww w.j  a va 2 s  .c o  m*/
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_about) {
    } else if (id == R.id.nav_add_location) {
        addLocationSetting();
        View view = findViewById(R.id.viewpager);
        Utility.showSnackbar(this, findViewById(R.id.viewpager), R.string.location_added);
    } else if (id == R.id.nav_remove_current_location) {
        Utility.deleteCurrentLocation(this);
        reInitializeNavigation();
        View view = findViewById(R.id.viewpager);
        Utility.showSnackbar(this, findViewById(R.id.viewpager), R.string.location_removed);
    } else if (id == R.id.nav_settings) {
        startActivity(new Intent(this, SettingsActivity.class));
        //            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        //            sp.registerOnSharedPreferenceChangeListener(this);
    } else {
        String locationSetting = item.getTitle().toString();
        //            long locationId = WetterSyncAdapter.getPreferredLocationCityId(this, locationSetting);
        //            if (locationId != 0) {
        //change the location, sync and update adapters
        Utility.setPreferredLocation(this, locationSetting);
        Utility.resetLocationStatus(this);
        Utility.setLastSync(this, System.currentTimeMillis() - 1000 * 60 * 10);
        WetterSyncAdapter.syncImmediately(this);
        Utility.showSnackbar(this, findViewById(R.id.viewpager), R.string.location_changed);
        //            }
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java

@Override
public void addAnnouncedServers(ArrayList<ServerAddress> servers) {
    mServersMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override//w  ww  .java  2s .  c o  m
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getSubMenu().size() < 1) {
                scanForServersMenu();
            }
            return false;
        }
    });

    for (ServerAddress server : servers) {
        final String name = server.name() != null ? server.name() : server.address().getHostName();
        final String serverNameKey = server.type() + "@" + name;
        mServersMenu.getSubMenu().add(serverNameKey);
        mServersMenu.getSubMenu().getItem(mServersMenu.getSubMenu().size() - 1)
                .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        ServerAddress server = mServers.get(item.getTitle());
                        if (server == null) {
                            return true;
                        }
                        RemoteApplication.getConfig().putServer(server, false);
                        rescanForServers();
                        return false;
                    }
                });
        mServers.put(serverNameKey, server);
    }
}