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:org.connectbot.HostEditorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_host_editor, container, false);

    mTransportItem = view.findViewById(R.id.protocol_item);
    mTransportItem.setOnClickListener(new View.OnClickListener() {
        @Override/* w  w  w.jav a2s  . co  m*/
        public void onClick(View v) {
            PopupMenu menu = new PopupMenu(getActivity(), v);
            for (String name : TransportFactory.getTransportNames()) {
                menu.getMenu().add(name);
            }
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    setTransportType(item.getTitle().toString(), /* setDefaultPortInModel */ true);
                    return true;
                }
            });
            menu.show();
        }
    });

    mTransportText = (TextView) view.findViewById(R.id.protocol_text);

    mQuickConnectContainer = (TextInputLayout) view.findViewById(R.id.quickconnect_field_container);

    mQuickConnectField = (EditText) view.findViewById(R.id.quickconnect_field);
    String oldQuickConnect = savedInstanceState == null ? null
            : savedInstanceState.getString(ARG_QUICKCONNECT_STRING);
    mQuickConnectField.setText(oldQuickConnect == null ? mHost.toString() : oldQuickConnect);
    mQuickConnectField.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (!mUriFieldEditInProgress) {
                applyQuickConnectString(s.toString(), mHost.getProtocol());

                mUriFieldEditInProgress = true;
                mUsernameField.setText(mHost.getUsername());
                mHostnameField.setText(mHost.getHostname());
                mPortField.setText(Integer.toString(mHost.getPort()));
                mUriFieldEditInProgress = false;
            }
        }
    });

    mExpandCollapseButton = (ImageButton) view.findViewById(R.id.expand_collapse_button);
    mExpandCollapseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setUriPartsContainerExpanded(!mIsUriEditorExpanded);
        }
    });

    mUriPartsContainer = view.findViewById(R.id.uri_parts_container);

    mUsernameContainer = view.findViewById(R.id.username_field_container);
    mUsernameField = (EditText) view.findViewById(R.id.username_edit_text);
    mUsernameField.setText(mHost.getUsername());
    mUsernameField.addTextChangedListener(new HostTextFieldWatcher(HostDatabase.FIELD_HOST_USERNAME));

    mHostnameContainer = view.findViewById(R.id.hostname_field_container);
    mHostnameField = (EditText) view.findViewById(R.id.hostname_edit_text);
    mHostnameField.setText(mHost.getHostname());
    mHostnameField.addTextChangedListener(new HostTextFieldWatcher(HostDatabase.FIELD_HOST_HOSTNAME));

    mPortContainer = view.findViewById(R.id.port_field_container);
    mPortField = (EditText) view.findViewById(R.id.port_edit_text);
    mPortField.setText(Integer.toString(mHost.getPort()));
    mPortField.addTextChangedListener(new HostTextFieldWatcher(HostDatabase.FIELD_HOST_PORT));

    mNicknameItem = view.findViewById(R.id.nickname_item);

    setTransportType(mHost.getProtocol(), /* setDefaultPortInModel */ false);

    mNicknameField = (EditText) view.findViewById(R.id.nickname_field);
    mNicknameField.setText(mHost.getNickname());
    mNicknameField.addTextChangedListener(new HostTextFieldWatcher(HostDatabase.FIELD_HOST_NICKNAME));

    mColorItem = view.findViewById(R.id.color_item);
    mColorItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu menu = new PopupMenu(getActivity(), v);
            for (int i = 0; i < mColorNames.length(); i++) {
                menu.getMenu().add(mColorNames.getText(i));
            }
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    for (int i = 0; i < mColorNames.length(); i++) {
                        if (item.getTitle().toString().equals(mColorNames.getText(i).toString())) {
                            mHost.setColor(mColorValues.getText(i).toString());
                            mColorText.setText(mColorNames.getText(i));
                            return true;
                        }
                    }
                    return false;
                }
            });
            menu.show();
        }
    });

    mColorText = (TextView) view.findViewById(R.id.color_text);
    for (int i = 0; i < mColorValues.length(); i++) {
        if (mColorValues.getText(i).toString().equals(mHost.getColor())) {
            mColorText.setText(mColorNames.getText(i));
            break;
        }
    }

    mFontSizeText = (EditText) view.findViewById(R.id.font_size_text);
    mFontSizeText.setText(Integer.toString(mHost.getFontSize()));
    mFontSizeTextChangeListener = new HostTextFieldWatcher(HostDatabase.FIELD_HOST_FONTSIZE);
    mFontSizeText.addTextChangedListener(mFontSizeTextChangeListener);
    mFontSizeText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus)
                mFontSizeText.setText(Integer.toString(mHost.getFontSize()));
        }
    });

    mFontSizeSeekBar = (SeekBar) view.findViewById(R.id.font_size_bar);
    mFontSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            setFontSize(MINIMUM_FONT_SIZE + progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    mFontSizeSeekBar.setProgress(mHost.getFontSize() - MINIMUM_FONT_SIZE);

    mPubkeyItem = view.findViewById(R.id.pubkey_item);
    mPubkeyItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu menu = new PopupMenu(getActivity(), v);
            for (String name : mPubkeyNames) {
                menu.getMenu().add(name);
            }
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    for (int i = 0; i < mPubkeyNames.size(); i++) {
                        if (mPubkeyNames.get(i).equals(item.getTitle())) {
                            mHost.setPubkeyId(Long.parseLong(mPubkeyValues.get(i)));
                            mPubkeyText.setText(mPubkeyNames.get(i));
                            return true;
                        }
                    }
                    return false;
                }
            });
            menu.show();
        }
    });

    mPubkeyText = (TextView) view.findViewById(R.id.pubkey_text);
    for (int i = 0; i < mPubkeyValues.size(); i++) {
        if (mHost.getPubkeyId() == Long.parseLong(mPubkeyValues.get(i))) {
            mPubkeyText.setText(mPubkeyNames.get(i));
            break;
        }
    }

    mDelKeyItem = view.findViewById(R.id.delkey_item);
    mDelKeyItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu menu = new PopupMenu(getActivity(), v);
            for (int i = 0; i < mDelKeyNames.length(); i++) {
                menu.getMenu().add(mDelKeyNames.getText(i));
            }
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    for (int i = 0; i < mDelKeyNames.length(); i++) {
                        if (mDelKeyNames.getText(i).equals(item.getTitle())) {
                            mHost.setDelKey(mDelKeyValues.getText(i).toString());
                            mDelKeyText.setText(mDelKeyNames.getText(i));
                            return true;
                        }
                    }
                    return false;
                }
            });
            menu.show();
        }
    });

    mDelKeyText = (TextView) view.findViewById(R.id.delkey_text);
    for (int i = 0; i < mDelKeyValues.length(); i++) {
        if (mDelKeyValues.getText(i).toString().equals(mHost.getDelKey())) {
            mDelKeyText.setText(mDelKeyNames.getText(i));
            break;
        }
    }

    mEncodingItem = view.findViewById(R.id.encoding_item);
    mEncodingItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu menu = new PopupMenu(getActivity(), v);
            for (String displayName : mCharsetData.keySet()) {
                menu.getMenu().add(displayName);
            }
            menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    for (String displayName : mCharsetData.keySet()) {
                        if (displayName.equals(item.getTitle())) {
                            mHost.setEncoding(mCharsetData.get(displayName));
                            mEncodingText.setText(displayName);
                            return true;
                        }
                    }
                    return false;
                }
            });
            menu.show();
        }
    });

    // The encoding text is initialized in setCharsetData() because Charset data is not always
    // available when this fragment is created.
    mEncodingText = (TextView) view.findViewById(R.id.encoding_text);

    mUseSshAuthSwitch = (CheckableMenuItem) view.findViewById(R.id.use_ssh_auth_item);
    mUseSshAuthSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            processSshAuthChange();
        }
    });

    mUseSshConfirmationSwitch = (CheckableMenuItem) view.findViewById(R.id.ssh_auth_confirmation_item);
    mUseSshAuthSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            processSshAuthChange();
        }
    });

    processSshAuthChange();

    mCompressionSwitch = (CheckableMenuItem) view.findViewById(R.id.compression_item);
    mCompressionSwitch.setChecked(mHost.getCompression());
    mCompressionSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mHost.setCompression(isChecked);
            handleHostChange();
        }
    });

    mStartShellSwitch = (CheckableMenuItem) view.findViewById(R.id.start_shell_item);
    mStartShellSwitch.setChecked(mHost.getWantSession());
    mStartShellSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mHost.setWantSession(isChecked);
            handleHostChange();
        }
    });

    mStayConnectedSwitch = (CheckableMenuItem) view.findViewById(R.id.stay_connected_item);
    mStayConnectedSwitch.setChecked(mHost.getStayConnected());
    mStayConnectedSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mHost.setStayConnected(isChecked);
            handleHostChange();
        }
    });

    mCloseOnDisconnectSwitch = (CheckableMenuItem) view.findViewById(R.id.close_on_disconnect_item);
    mCloseOnDisconnectSwitch.setChecked(mHost.getQuickDisconnect());
    mCloseOnDisconnectSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mHost.setQuickDisconnect(isChecked);
            handleHostChange();
        }
    });

    mPostLoginAutomationField = (EditText) view.findViewById(R.id.post_login_automation_field);
    mPostLoginAutomationField.setText(mHost.getPostLogin());
    mPostLoginAutomationField
            .addTextChangedListener(new HostTextFieldWatcher(HostDatabase.FIELD_HOST_POSTLOGIN));

    setUriPartsContainerExpanded(mIsUriEditorExpanded);

    return view;
}

From source file:com.commonsware.android.diceware.PassphraseFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.open:
        open();/*ww w .j  av  a 2 s  . c  om*/
        return (true);

    case R.id.get:
        get();
        return (true);

    case R.id.refresh:
        loadWords(false, true);
        return (true);

    case R.id.reset:
        prefs.edit().clear().apply();
        loadWords(true, true);
        return (true);

    case R.id.word_count_4:
    case R.id.word_count_5:
    case R.id.word_count_6:
    case R.id.word_count_7:
    case R.id.word_count_8:
    case R.id.word_count_9:
    case R.id.word_count_10:
        item.setChecked(!item.isChecked());

        int temp = Integer.parseInt(item.getTitle().toString());

        if (temp != wordCount) {
            wordCount = temp;
            loadWords(false, true);
        }

        return (true);
    }

    return (super.onOptionsItemSelected(item));
}

From source file:com.master.metehan.filtereagle.ActivityMain.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.i(TAG, "Menu=" + item.getTitle());

    // Handle item selection
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    switch (item.getItemId()) {
    case R.id.menu_app_user:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("show_user", item.isChecked()).apply();
        return true;

    case R.id.menu_app_system:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("show_system", item.isChecked()).apply();
        return true;

    case R.id.menu_app_nointernet:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("show_nointernet", item.isChecked()).apply();
        return true;

    case R.id.menu_app_disabled:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("show_disabled", item.isChecked()).apply();
        return true;

    case R.id.menu_sort_name:
        item.setChecked(true);/*from  w w w .  j a va2s. c om*/
        prefs.edit().putString("sort", "name").apply();
        return true;

    case R.id.menu_sort_uid:
        item.setChecked(true);
        prefs.edit().putString("sort", "uid").apply();
        return true;

    case R.id.menu_sort_data:
        item.setChecked(true);
        prefs.edit().putString("sort", "data").apply();
        return true;

    case R.id.menu_log:
        if (IAB.isPurchased(ActivityPro.SKU_LOG, this))
            startActivity(new Intent(this, ActivityLog.class));
        else
            startActivity(new Intent(this, ActivityPro.class));
        return true;

    case R.id.menu_settings:
        startActivity(new Intent(this, ActivitySettings.class));
        return true;

    case R.id.menu_pro:
        startActivity(new Intent(ActivityMain.this, ActivityPro.class));
        return true;

    case R.id.menu_invite:
        startActivityForResult(getIntentInvite(this), REQUEST_INVITE);
        return true;

    case R.id.menu_legend:
        menu_legend();
        return true;

    case R.id.menu_support:
        startActivity(getIntentSupport());
        return true;

    case R.id.menu_about:
        menu_about();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaGalleryFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    menu.clear();//from  w ww .  j  av a  2s .  c  o m
    // Add Menu Button
    mUpdateItem = menu.add(R.string.theta_update);
    if (mDevice != null) {
        mUpdateItem.setVisible(true);
    } else {
        mUpdateItem.setVisible(false);
    }
    mUpdateItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    mUpdateItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            if (item.getTitle().equals(mUpdateItem.getTitle())) {
                ShootingModeGetTask mode = new ShootingModeGetTask();
                mDownloadTask = new DownloadThetaDataTask();
                mDownloadTask.execute(mode);
            }
            return true;
        }
    });
}

From source file:android_network.hetnet.vpn_service.AdapterRule.java

private void markPro(MenuItem menu, String sku) {
    if (true) {/*from ww  w  .j  a v a2  s .  c  om*/
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean dark = prefs.getBoolean("dark_theme", false);
        SpannableStringBuilder ssb = new SpannableStringBuilder("  " + menu.getTitle());
        ssb.setSpan(
                new ImageSpan(context,
                        dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp),
                0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        menu.setTitle(ssb);
    }
}

From source file:cz.jaro.alarmmorning.AlarmMorningActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // The action bar home/up action should open or close the drawer.
        if (isNavigationDrawerOpen())
            closeNavigationDrawer();/*from  w w  w. j a  v a 2  s .  c  om*/
        else
            openNavigationDrawer();
        return true;

    case R.id.navigation_calendar:
        CalendarFragment calendarFragment = new CalendarFragment();
        mFragment = calendarFragment;

        // Insert the mFragment by replacing any existing mFragment
        getFragmentManager().beginTransaction().replace(R.id.content_frame, mFragment).commit();

        // Highlight the selected item, update the title, and close the drawer
        highlightMenuItem(item);
        setFragmentTitle(item.getTitle());
        break;

    case R.id.navigation_defaults:
        Intent defaultsActivityIntent = new Intent(this, DefaultsActivity.class);
        startActivity(defaultsActivityIntent);
        break;

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

    case R.id.navigation_website:
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(browserIntent);
        break;

    default:
        return super.onOptionsItemSelected(item);
    }

    closeNavigationDrawer();
    return true;
}

From source file:com.ibm.iot.android.iotstarter.fragments.LogPagerFragment.java

/**
 * Process the selected iot_menu item./*from  www .  j a  v  a  2 s  . c  o m*/
 * @param item The selected iot_menu item.
 * @return true in all cases.
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.d(TAG, ".onOptionsItemSelected() entered");
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_profiles:
        if (!ProfilesActivity.class.getName().equals(app.getCurrentRunningActivity())) {
            openProfiles();
        }
        return true;
    case R.id.action_tutorial:
        openTutorial();
        return true;
    case R.id.action_web:
        openWeb();
        return true;
    case R.id.action_accel:
        app.toggleAccel();
        return true;
    case R.id.clear:
        app.setUnreadCount(0);
        app.getMessageLog().clear();
        listAdapter.notifyDataSetInvalidated();
        return true;
    case R.id.action_clear_profiles:
        app.clearProfiles();
        return true;
    default:
        if (item.getTitle().equals(getResources().getString(R.string.app_name))) {
            getActivity().openOptionsMenu();
            return true;
        } else {
            return super.onOptionsItemSelected(item);
        }
    }
}

From source file:org.tigase.messenger.phone.pro.MainActivity.java

private void switchMainFragment(final int id) {
    final MenuItem menuItem = navigationMenu.findItem(id);

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    switch (id) {
    case R.id.nav_about: {
        Intent intent = new Intent(this, AboutActivity.class);
        startActivity(intent);/*www . j  a v  a 2 s .com*/
        break;
    }
    case R.id.nav_connectionstatus: {
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.flContent, ConnectionStatusesFragment.newInstance())
                .commit();

        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString("menu", "connectionstatus");
        editor.commit();
        menuItem.setChecked(true);
        setTitle(menuItem.getTitle());

        break;
    }
    case R.id.nav_roster: {
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.flContent, RosterItemFragment.newInstance(mServiceConnection)).commit();

        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString("menu", "roster");
        editor.commit();
        menuItem.setChecked(true);
        setTitle(menuItem.getTitle());

        break;
    }
    case R.id.nav_chats: {
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.flContent, OpenChatItemFragment.newInstance(mServiceConnection)).commit();

        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString("menu", "chats");
        editor.commit();
        menuItem.setChecked(true);
        setTitle(menuItem.getTitle());

        break;
    }
    case R.id.nav_joinmuc: {
        Intent intent = new Intent(this, JoinMucActivity.class);
        startActivity(intent);
        break;
    }
    case R.id.nav_settings: {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
        break;
    }
    }
}

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

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

    // If delete pressed in context menu, call deleteNote method with position as argument
    if (item.getTitle() == getResources().getString(R.string.action_delete)) {
        deleteNote(this, info.position);

        return true;
    }/*from ww  w. j  av  a 2s  . c o m*/

    return false;
}

From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem item = menu.add(Menu.NONE, ACTIONBAR_MENU_ITEM_SUMMIT, Menu.NONE, getString(R.string.menu_take));
    SpannableString spanString = new SpannableString(item.getTitle().toString());
    spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white
    item.setTitle(spanString);//from w  w w  .  ja v  a2 s  . co m

    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    super.onCreateOptionsMenu(menu, inflater);
}