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.songcode.materialnotes.ui.NotesListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        toggleDrawerLayout();//w  ww  . j  a v  a  2s.  c  o m
        break;
    case R.id.menu_new_folder: {
        showCreateOrModifyFolderDialog(true);
        break;
    }
    case R.id.menu_export_text: {
        exportNoteToText();
        break;
    }
    case R.id.menu_sync: {
        if (isSyncMode()) {
            if (TextUtils.equals(item.getTitle(), getString(R.string.menu_sync))) {
                GTaskSyncService.startSync(this);
            } else {
                GTaskSyncService.cancelSync(this);
            }
        } else {
            startPreferenceActivity();
        }
        break;
    }
    case R.id.menu_setting: {
        startPreferenceActivity();
        break;
    }
    case R.id.menu_new_note: {
        createNewNote();
        break;
    }
    case R.id.menu_search:
        onSearchRequested();
        break;
    default:
        break;
    }
    return true;
}

From source file:com.folioreader.ui.folio.activity.FolioActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    //Log.d(LOG_TAG, "-> onOptionsItemSelected -> " + item.getItemId());

    int itemId = item.getItemId();

    if (itemId == android.R.id.home) {
        Log.v(LOG_TAG, "-> onOptionsItemSelected -> drawer");
        startContentHighlightActivity();
        return true;

    } else if (itemId == R.id.itemSearch) {
        Log.v(LOG_TAG, "-> onOptionsItemSelected -> " + item.getTitle());
        if (searchUri == null)
            return true;
        Intent intent = new Intent(this, SearchActivity.class);
        intent.putExtra(SearchActivity.BUNDLE_SEARCH_URI, searchUri);
        intent.putExtra(SearchAdapter.DATA_BUNDLE, searchAdapterDataBundle);
        intent.putExtra(SearchActivity.BUNDLE_SAVE_SEARCH_QUERY, searchQuery);
        startActivityForResult(intent, RequestCode.SEARCH.value);
        return true;

    } else if (itemId == R.id.itemConfig) {
        Log.v(LOG_TAG, "-> onOptionsItemSelected -> " + item.getTitle());
        showConfigBottomSheetDialogFragment();
        return true;

    } else if (itemId == R.id.itemTts) {
        Log.v(LOG_TAG, "-> onOptionsItemSelected -> " + item.getTitle());
        showMediaController();//from ww  w.ja  va 2 s.  c  o  m
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Get pressed item information
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    // If Rename Tag pressed
    if (item.getTitle().equals(getResources().getString(R.string.rename_context_menu))) {
        // Create new EdiText and configure
        final EditText tagTitle = new EditText(this);
        tagTitle.setSingleLine(true);/* w  w  w.jav a2 s . c om*/
        tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

        // Set tagTitle maxLength
        int maxLength = 50;
        InputFilter[] array = new InputFilter[1];
        array[0] = new InputFilter.LengthFilter(maxLength);
        tagTitle.setFilters(array);

        // Get tagName text into EditText
        try {
            assert info != null;
            tagTitle.setText(tags.getJSONObject(info.position).getString("tagName"));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        final LinearLayout l = new LinearLayout(this);

        l.setOrientation(LinearLayout.VERTICAL);
        l.addView(tagTitle);

        // Show rename dialog
        new AlertDialog.Builder(this).setTitle(R.string.rename_tag_dialog_title).setView(l)
                .setPositiveButton(R.string.rename_tag_dialog_button, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 'Rename' pressed, change tagName and store
                        try {
                            JSONObject newTagName = tags.getJSONObject(info.position);
                            newTagName.put("tagName", tagTitle.getText());

                            tags.put(info.position, newTagName);
                            adapter.notifyDataSetChanged();

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        writeToJSON();

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_renamed,
                                Toast.LENGTH_SHORT);
                        toast.show();

                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);
                    }
                }).show();
        tagTitle.requestFocus();
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

        return true;
    }

    // If Delete Tag pressed
    else if (item.getTitle().equals(getResources().getString(R.string.delete_context_menu))) {
        // Construct dialog message
        String dialogMessage = "";

        assert info != null;
        try {
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog1) + " '"
                    + tags.getJSONObject(info.position).getString("tagName") + "'?";

        } catch (JSONException e) {
            e.printStackTrace();
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog2);
        }

        // Show delete dialog
        new AlertDialog.Builder(this).setMessage(dialogMessage)
                .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JSONArray newArray = new JSONArray();

                        // Copy contents to new array, without the deleted item
                        for (int i = 0; i < tags.length(); i++) {
                            if (i != info.position) {
                                try {
                                    newArray.put(tags.get(i));

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                        // Equal original array to new array
                        tags = newArray;

                        // Write to file
                        try {
                            settings.put("tags", tags);
                            root.put("settings", settings);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        writeToJSON();

                        adapter.adapterData = tags;
                        adapter.notifyDataSetChanged();

                        updateListViewHeight(listView);

                        // If no tags, show 'Press + to add Tags' textView
                        if (tags.length() == 0)
                            noTags.setVisibility(View.VISIBLE);

                        else
                            noTags.setVisibility(View.INVISIBLE);

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_deleted,
                                Toast.LENGTH_SHORT);
                        toast.show();

                    }
                }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Do nothing, close dialog
                    }
                }).show();

        return true;
    }

    return super.onContextItemSelected(item);
}

From source file:com.ruesga.rview.MainActivity.java

private void performNavigateTo() {
    final Menu menu = mBinding.drawerNavigationView.getMenu();
    final MenuItem item = menu.findItem(mModel.currentNavigationItemId);
    if (item == null || mAccount == null) {
        return;// w  w  w .  j a  v  a2s.  c o  m
    }

    switch (item.getItemId()) {
    case R.id.menu_dashboard:
        openDashboardFragment();
        break;

    default:
        // Is a filter menu?
        mModel.filterQuery = getQueryFilterExpressionFromMenuItemId(item.getItemId());
        if (mModel.filterQuery != null) {
            mModel.filterName = item.getTitle().toString().split(DrawerNavigationView.SEPARATOR)[0];
            openFilterFragment(item.getItemId(), mModel.filterName, mModel.filterQuery);
        }
        break;
    }
}

From source file:com.arlib.floatingsearchviewdemo.MainActivity.java

private void setupFloatingSearch() {
    mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {

        @Override//from www .  ja v  a2 s  . co m
        public void onSearchTextChanged(String oldQuery, final String newQuery) {

            if (!oldQuery.equals("") && newQuery.equals("")) {
                mSearchView.clearSuggestions();
            } else {

                //this shows the top left circular progress
                //you can call it where ever you want, but
                //it makes sense to do it when loading something in
                //the background.
                mSearchView.showProgress();

                //simulates a query call to a data source
                //with a new query.
                DataHelper.findSuggestions(MainActivity.this, newQuery, 5, FIND_SUGGESTION_SIMULATED_DELAY,
                        new DataHelper.OnFindSuggestionsListener() {

                            @Override
                            public void onResults(List<ColorSuggestion> results) {

                                //this will swap the data and
                                //render the collapse/expand animations as necessary
                                mSearchView.swapSuggestions(results);

                                //let the users know that the background
                                //process has completed
                                mSearchView.hideProgress();
                            }
                        });
            }

            Log.d(TAG, "onSearchTextChanged()");
        }
    });

    mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
        @Override
        public void onSuggestionClicked(SearchSuggestion searchSuggestion) {

            ColorSuggestion colorSuggestion = (ColorSuggestion) searchSuggestion;
            DataHelper.findColors(MainActivity.this, colorSuggestion.getBody(),
                    new DataHelper.OnFindColorsListener() {

                        @Override
                        public void onResults(List<ColorWrapper> results) {
                            mSearchResultsAdapter.swapData(results);
                        }

                    });
            Log.d(TAG, "onSuggestionClicked()");
        }

        @Override
        public void onSearchAction(String query) {

            DataHelper.findColors(MainActivity.this, query, new DataHelper.OnFindColorsListener() {

                @Override
                public void onResults(List<ColorWrapper> results) {
                    mSearchResultsAdapter.swapData(results);
                }

            });
            Log.d(TAG, "onSearchAction()");
        }
    });

    mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
        @Override
        public void onFocus() {
            mSearchView.clearQuery();

            //show suggestions when search bar gains focus (typically history suggestions)
            mSearchView.swapSuggestions(DataHelper.getHistory(MainActivity.this, 3));

            Log.d(TAG, "onFocus()");
        }

        @Override
        public void onFocusCleared() {

            Log.d(TAG, "onFocusCleared()");
        }
    });

    //handle menu clicks the same way as you would
    //in a regular activity
    mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() {
        @Override
        public void onActionMenuItemSelected(MenuItem item) {

            if (item.getItemId() == R.id.action_change_colors) {

                mIsDarkSearchTheme = true;

                //demonstrate setting colors for items
                mSearchView.setBackgroundColor(Color.parseColor("#787878"));
                mSearchView.setViewTextColor(Color.parseColor("#e9e9e9"));
                mSearchView.setHintTextColor(Color.parseColor("#e9e9e9"));
                mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9"));
                mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9"));
                mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
                mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9"));
                mSearchView.setDividerColor(Color.parseColor("#BEBEBE"));
                mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
            } else {

                //just print action
                Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
            }

        }
    });

    //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHamburger"
    mSearchView.setOnLeftMenuClickListener(new FloatingSearchView.OnLeftMenuClickListener() {
        @Override
        public void onMenuOpened() {

            Log.d(TAG, "onMenuOpened()");
            mDrawerLayout.openDrawer(GravityCompat.START);
        }

        @Override
        public void onMenuClosed() {
            Log.d(TAG, "onMenuClosed()");
        }
    });

    //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome"
    mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() {
        @Override
        public void onHomeClicked() {

            Log.d(TAG, "onHomeClicked()");
        }
    });

    /*
     * Here you have access to the left icon and the text of a given suggestion
     * item after as it is bound to the suggestion list. You can utilize this
     * callback to change some properties of the left icon and the text. For example, you
     * can load the left icon images using your favorite image loading library, or change text color.
     *
     *
     * Important:
     * Keep in mind that the suggestion list is a RecyclerView, so views are reused for different
     * items in the list.
     */
    mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView,
                SearchSuggestion item, int itemPosition) {
            ColorSuggestion colorSuggestion = (ColorSuggestion) item;

            String textColor = mIsDarkSearchTheme ? "#ffffff" : "#000000";
            String textLight = mIsDarkSearchTheme ? "#bfbfbf" : "#787878";

            if (colorSuggestion.getIsHistory()) {
                leftIcon.setImageDrawable(
                        ResourcesCompat.getDrawable(getResources(), R.drawable.ic_history_black_24dp, null));

                Util.setIconColor(leftIcon, Color.parseColor(textColor));
                leftIcon.setAlpha(.36f);
            } else {
                leftIcon.setAlpha(0.0f);
                leftIcon.setImageDrawable(null);
            }

            textView.setTextColor(Color.parseColor(textColor));
            String text = colorSuggestion.getBody().replaceFirst(mSearchView.getQuery(),
                    "<font color=\"" + textLight + "\">" + mSearchView.getQuery() + "</font>");
            textView.setText(Html.fromHtml(text));
        }

    });

    //listen for when suggestion list expands/shrinks in order to move down/up the
    //search results list
    mSearchView.setOnSuggestionsListHeightChanged(new FloatingSearchView.OnSuggestionsListHeightChanged() {
        @Override
        public void onSuggestionsListHeightChanged(float newHeight) {
            mSearchResultsList.setTranslationY(newHeight);
        }
    });
}

From source file:com.crearo.gpslogger.GpsMainActivity.java

@Override
public boolean onMenuItemClick(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();

    LOG.debug("Menu Item: " + String.valueOf(item.getTitle()));

    switch (id) {
    case R.id.mnuAnnotate:
        annotate();/* w w  w .jav a  2s.co  m*/
        return true;
    case R.id.mnuOnePoint:
        logSinglePoint();
        return true;
    case R.id.mnuShare:
        share();
        return true;
    case R.id.mnuOSM:
        uploadToOpenStreetMap();
        return true;
    case R.id.mnuDropBox:
        uploadToDropBox();
        return true;
    case R.id.mnuGDocs:
        uploadToGoogleDocs();
        return true;
    case R.id.mnuOpenGTS:
        sendToOpenGTS();
        return true;
    case R.id.mnuFtp:
        sendToFtp();
        return true;
    case R.id.mnuEmail:
        selectAndEmailFile();
        return true;
    case R.id.mnuAutoSendNow:
        forceAutoSendNow();
    case R.id.mnuOwnCloud:
        uploadToOwnCloud();
        return true;
    default:
        return true;
    }
}

From source file:com.rareventure.gps2.reviewer.map.OsmMapGpsTrailerReviewerMapActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    GTG.cacheCreatorLock.registerReadingThread();
    try {// ww w  .ja va2  s . co m
        if (item.getTitle().equals(getText(R.string.settings))) {
            startInternalActivity(new Intent(this, SettingsActivity.class));
            return true;
        } else if (item.getTitle().equals(getText(R.string.turn_off_photos))) {
            prefs.showPhotos = false;
            gpsTrailerOverlay.notifyViewNodesChanged();

            if (mediaGalleryFragment != null)
                mediaGalleryFragment.finishBrowsing();
            return true;
        } else if (item.getTitle().equals(getText(R.string.turn_on_photos))) {
            prefs.showPhotos = true;
            gpsTrailerOverlay.notifyViewNodesChanged();
            return true;
        } else if (item.getTitle().equals(getText(R.string.help))) {
            startInternalActivity(new Intent(this, ShowManual.class));
            return true;
        }

        return super.onOptionsItemSelected(item);
    } finally {
        GTG.cacheCreatorLock.unregisterReadingThread();
    }
}

From source file:com.biscofil.defcon2016.MainActivity.java

public void selectDrawerItem(MenuItem menuItem) {
    if (menuItem.getItemId() == R.id.menu_web) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(getString(R.string.web_url)));
        startActivity(i);//from  w  ww.j a v a2s  . c o  m
    } else if (!menuItem.isChecked()) {
        switch (menuItem.getItemId()) {
        case R.id.menu_menu:
            setFragmentContent(this, Menu_fragment.class, menuItem, true);
            break;
        case R.id.menu_meter:
            setFragmentContent(this, Meter_fragment.class, menuItem, false);
            break;
        case R.id.menu_map:
            setFragmentContent(this, Map_fragment.class, menuItem, false);
            break;
        case R.id.menu_guida:
            setFragmentContent(this, Guida_fragment.class, menuItem, false);
            break;
        case R.id.menu_calc:
            setFragmentContent(this, GuidaCalcoloIndice_fragment.class, menuItem, false);
            break;
        case R.id.menu_license:
            setFragmentContent(this, Licenze_fragment.class, menuItem, false);
            break;
        case R.id.menu_credits:
            setFragmentContent(this, Credits_fragment.class, menuItem, false);
            break;
        default:
            setFragmentContent(this, Map_fragment.class, menuItem, false);
        }
        menuItem.setChecked(true);
        setTitle(menuItem.getTitle());
        mDrawer.closeDrawers();
    }
}

From source file:free.yhc.feeder.ChannelListActivity.java

private void onOpt_addChannel_youtubeEditDiag(final MenuItem item) {
    // Set action for dialog.
    final EditTextDialogAction action = new EditTextDialogAction() {
        @Override//from w w  w. java2  s  . c om
        public void prepare(Dialog dialog, EditText edit) {
        }

        @Override
        public void onOk(Dialog dialog, EditText edit) {
            switch (item.getItemId()) {
            case R.id.uploader:
                addChannel(Utils.buildYoutubeFeedUrl_uploader(edit.getText().toString()), null);
                break;
            case R.id.search:
                addChannel(Utils.buildYoutubeFeedUrl_search(edit.getText().toString()), null);
                break;
            default:
                eAssert(false);
            }
        }
    };
    UiHelper.buildOneLineEditTextDialog(this, item.getTitle(), action).show();
}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

private boolean setSearchMode(boolean search) {
    if (searchMode != search) {
        searchMode = search;/* w  w w. j  a v  a  2 s .c  o m*/
        if (search) {
            if (currentMenu != null) {
                MenuItem menuItem = currentMenu.findItem(ListPage.OPTIONS_MENU_SEARCH);
                if (menuItem != null) {
                    getSearchView(true).setQueryHint(menuItem.getTitle());
                }
            }
        }
        if (page != null) {
            if (search) {
                page.onSearchQueryChange(getSearchView(true).getQuery().toString());
            } else {
                page.onSearchQueryChange("");
                page.onSearchCancel();
            }
        }
        setActionBarLocked(LOCKER_SEARCH, search);
        invalidateOptionsMenu();
        invalidateHomeUpState();
        return true;
    }
    return false;
}