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:ca.nehil.rter.streamingapp2.StreamingActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getTitle().equals("Start")) {
        if (!recording) {
            Log.d(TAG, "attemptHandshaking");
            attemptHandshake();//from  ww  w . j  a  v  a2s .c o m
            Log.w(LOG_TAG, "Start Button Pushed");
            item.setTitle("Stop");
        }

    } else if (item.getTitle().equals("Stop")) {
        stopRecording();
        Log.w(LOG_TAG, "Stop Button Pushed");
        item.setTitle("Start");
    }
    return super.onOptionsItemSelected(item);
}

From source file:br.com.gabrielmonteiro.urbancoffee.view.activity.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//from  w  ww . j a va 2  s . c o  m
public boolean onNavigationItemSelected(MenuItem item) {
    Class fragmentClass = null;
    boolean isAlert = false;
    int id = item.getItemId();

    if (id == R.id.nav_store) {
        fragmentClass = StoreFragment.class;
    } else if (id == R.id.nav_payments) {
        fragmentClass = PaymentsListFragment.class;
    } else if (id == R.id.nav_license) {
        fragmentClass = LicenseFragment.class;
    } else if (id == R.id.nav_about) {
        isAlert = true;
    }

    if (isAlert) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle(getString(R.string.about_text_title));
        alertDialogBuilder.setMessage(getString(R.string.about_text_msg));
        alertDialogBuilder.setNeutralButton(getString(R.string.ok), getNegativeAction());
        alertDialogBuilder.show();
    } else {
        openFragment(fragmentClass);
        item.setChecked(true);
        setTitle(item.getTitle());
    }
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.zhengde163.netguard.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:
        boolean nointernet = prefs.getBoolean("show_nointernet", true);
        nointernet = !nointernet;/*from   ww w . j  a  v  a2 s . co  m*/
        if (nointernet)
            item.setIcon(R.drawable.checked);
        else
            item.setIcon(R.drawable.check);
        prefs.edit().putBoolean("show_nointernet", nointernet).apply();
        return true;

    case R.id.menu_app_disabled:
        boolean disabled = prefs.getBoolean("show_disabled", true);
        disabled = !disabled;
        if (disabled)
            item.setIcon(R.drawable.checked);
        else
            item.setIcon(R.drawable.check);
        prefs.edit().putBoolean("show_disabled", disabled).apply();
        return true;

    case R.id.menu_sort_name:
        item.setChecked(true);
        item.setIcon(R.drawable.singlechecked);
        menu_data.setIcon(R.drawable.singlecheck);
        prefs.edit().putString("sort", "name").apply();
        return true;

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

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

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

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

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

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

From source file:com.money.manager.ex.home.HomeFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    boolean result = false;

    // get account id
    QueryAccountBills account = getSelectedAccount(item);
    if (account == null)
        return false;

    int accountId = account.getAccountId();

    // get the action
    String menuItemTitle = item.getTitle().toString();

    if (menuItemTitle.equalsIgnoreCase(getString(R.string.edit))) {
        Intent intent = new Intent(getActivity(), AccountEditActivity.class);
        intent.putExtra(AccountEditActivity.KEY_ACCOUNT_ID, accountId);
        intent.setAction(Intent.ACTION_EDIT);
        startActivity(intent);/*w  w w  .j  a v a  2  s  .co  m*/

        result = true;
    }
    if (menuItemTitle.equalsIgnoreCase(getString(R.string.balance_account))) {
        startBalanceAccount(account);
    }
    if (menuItemTitle.equalsIgnoreCase(getString(R.string.portfolio))) {
        EventBus.getDefault().post(new RequestPortfolioFragmentEvent(accountId));
    }

    return result;
}

From source file:com.gh4a.fragment.EventListFragment.java

public boolean open(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    Event event = (Event) mAdapter.getItem(info.position);
    EventRepository eventRepo = event.getRepo();
    String[] repoNamePart = eventRepo.getName().split("/");
    String repoOwner = null;//from www .  j a  va 2 s .  c  o  m
    String repoName = null;
    if (repoNamePart.length == 2) {
        repoOwner = repoNamePart[0];
        repoName = repoNamePart[1];
    }

    String title = item.getTitle().toString();
    String value = title.split(" ")[1];

    Gh4Application context = ((BaseSherlockFragmentActivity) getActivity()).getApplicationContext();

    /** User item */
    if (title.startsWith("User")) {
        context.openUserInfoActivity(getSherlockActivity(), value, null);
    }
    /** Repo item */
    else if (title.startsWith("Repo")) {
        context.openRepositoryInfoActivity(getSherlockActivity(), repoOwner, repoName, 0);
    }
    /** Commit item */
    else if (title.startsWith("Commit")) {
        if (repoOwner != null) {
            context.openCommitInfoActivity(getSherlockActivity(), repoOwner, repoName, value, 0);
        } else {
            context.notFoundMessage(getSherlockActivity(), R.plurals.repository);
        }
    }
    /** Issue comment item */
    else if (title.startsWith("Open issues")) {
        context.openIssueListActivity(getSherlockActivity(), repoOwner, repoName,
                Constants.Issue.ISSUE_STATE_OPEN);
    }
    /** Issue item */
    else if (title.startsWith("Issue")) {
        IssuesPayload payload = (IssuesPayload) event.getPayload();
        context.openIssueActivity(getSherlockActivity(), repoOwner, repoName, payload.getIssue().getNumber());
    }
    /** Commit comment item */
    else if (title.startsWith("Comment in browser")) {
        CommitCommentPayload payload = (CommitCommentPayload) event.getPayload();
        context.openBrowser(getSherlockActivity(), payload.getComment().getUrl());
    }
    /** Gist item */
    else if (title.startsWith("Gist")) {
        GistPayload payload = (GistPayload) event.getPayload();
        context.openGistActivity(getSherlockActivity(), payload.getGist().getUser().getLogin(),
                payload.getGist().getId(), 0);
    }
    /** Download item */
    else if (title.startsWith("File")) {
        if (repoOwner != null) {
            DownloadPayload payload = (DownloadPayload) event.getPayload();
            context.openBrowser(getSherlockActivity(), payload.getDownload().getHtmlUrl());
        } else {
            context.notFoundMessage(getSherlockActivity(), R.plurals.repository);
        }
    }
    /** Fork item */
    else if (title.startsWith("Forked repo")) {
        ForkPayload payload = (ForkPayload) event.getPayload();
        Repository forkee = payload.getForkee();
        if (forkee != null) {
            context.openRepositoryInfoActivity(getSherlockActivity(), forkee);
        } else {
            context.notFoundMessage(getSherlockActivity(), R.plurals.repository);
        }
    }
    /** Wiki item */
    else if (title.startsWith("Wiki in browser")) {
        GollumPayload payload = (GollumPayload) event.getPayload();
        List<GollumPage> pages = payload.getPages();
        if (pages != null && !pages.isEmpty()) {//TODO: now just open the first page
            context.openBrowser(getSherlockActivity(), pages.get(0).getHtmlUrl());
        }
    }
    /** Pull Request item */
    else if (title.startsWith("Pull request")) {
        PullRequestPayload payload = (PullRequestPayload) event.getPayload();
        context.openPullRequestActivity(getSherlockActivity(), repoOwner, repoName, payload.getNumber());
    }

    else if (title.startsWith("Compare")) {
        if (repoOwner != null) {
            PushPayload payload = (PushPayload) event.getPayload();

            Intent intent = new Intent().setClass(context, CompareActivity.class);
            intent.putExtra(Constants.Repository.REPO_OWNER, repoOwner);
            intent.putExtra(Constants.Repository.REPO_NAME, repoName);
            intent.putExtra(Constants.Repository.HEAD, payload.getHead());
            intent.putExtra(Constants.Repository.BASE, payload.getBefore());
            startActivity(intent);
        }
    }
    return true;
}

From source file:com.egoclean.testpregnancy.util.ActivityHelper.java

/**
 * Adds an action button to the compatibility action bar, using menu information from a
 * {@link android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state
 * can be changed to show a loading spinner using
 * {@link ActivityHelper#setRefreshActionButtonCompatState(boolean)}.
 *///from w ww  .j  a  v  a2s. c  o m
private View addActionButtonCompatFromMenuItem(final MenuItem item) {
    final ViewGroup actionBar = getActionBarCompat();
    if (actionBar == null) {
        return null;
    }

    // Create the separator
    ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle);
    separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT));

    // Create the button
    ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle);
    actionButton.setId(item.getItemId());
    actionButton.setLayoutParams(new ViewGroup.LayoutParams(
            (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height),
            ViewGroup.LayoutParams.FILL_PARENT));
    actionButton.setImageDrawable(item.getIcon());
    actionButton.setScaleType(ImageView.ScaleType.CENTER);
    actionButton.setContentDescription(item.getTitle());
    actionButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
        }
    });

    actionBar.addView(separator);
    actionBar.addView(actionButton);

    if (item.getItemId() == R.id.menu_refresh) {
        // Refresh buttons should be stateful, and allow for indeterminate progress indicators,
        // so add those.
        int buttonWidth = mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height);
        int buttonWidthDiv3 = buttonWidth / 3;
        ProgressBar indicator = new ProgressBar(mActivity, null, R.attr.actionbarCompatProgressIndicatorStyle);
        LinearLayout.LayoutParams indicatorLayoutParams = new LinearLayout.LayoutParams(buttonWidthDiv3,
                buttonWidthDiv3);
        indicatorLayoutParams.setMargins(buttonWidthDiv3, buttonWidthDiv3, buttonWidth - 2 * buttonWidthDiv3,
                0);
        indicator.setLayoutParams(indicatorLayoutParams);
        indicator.setVisibility(View.GONE);
        indicator.setId(R.id.menu_refresh_progress);
        actionBar.addView(indicator);
    }

    return actionButton;
}

From source file:org.ozonecity.gpslogger2.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();

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

    switch (id) {
    case R.id.mnuAnnotate:
        Annotate();// w  w w  . j  a  v a  2  s .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();
    default:
        return true;
    }
}

From source file:nyc.c4q.jordansmith.finefree.ActivityMain.java

private void setupCarMenu() {
    for (int i = 0; i < cars.size(); i++) {
        submenu.clear();//from w  w w  .  j a v a  2 s  . c  o  m
        submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString())
                .setIcon(R.drawable.ic_car_black_36dp);

        final MenuItem item = submenu.getItem(i);
        Button button = new Button(this);
        button.setText("Remove");
        button.setTextColor(ContextCompat.getColor(this, R.color.white));
        item.setActionView(button);
        button.setBackground(getDrawable(R.drawable.button_shape));
        item.getActionView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new AlertDialog.Builder(ActivityMain.this).setIcon(android.R.drawable.ic_dialog_alert)
                        .setTitle("Delete Car").setMessage("Are you sure you want to remove car?")
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                System.out.println("CLICKED " + item.getTitle());
                                cupboard().withDatabase(db).delete(Car.class, "name = ?",
                                        (String) item.getTitle());

                                updateSubmenu();
                            }
                        }).setNegativeButton("Cancel", null).show();

            }
        });

    }
}

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

/**
 * Handles menu item selection// w ww  .j a  v  a 2  s. com
 */
@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();

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

    switch (id) {
    case R.id.mnuAnnotate:
        Annotate();
        return true;
    case R.id.mnuOnePoint:
        LogSinglePoint();
        return true;
    case R.id.mnuShare:
        Share();
        return true;
    case R.id.mnuEmail:
        SelectAndEmailFile();
        return true;
    case R.id.mnuAutoSendNow:
        ForceAutoSendNow();
    default:
        return super.onOptionsItemSelected(item);
    }

}

From source file:com.white.bihudaily.module.dailys.DailyActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from   w  ww.j  a va2s  .com*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            int themeId = menuItem.getOrder();
            switch (menuItem.getItemId()) {
            case R.id.menu_main_page:
                // 
                mDailyFragment = (DailyFragment) getSupportFragmentManager()
                        .findFragmentByTag(Constant.TAG_MAIN);
                if (mDailyFragment == null) {
                    mDailyFragment = new DailyFragment();
                }
                switchFragment(mDailyFragment, Constant.TAG_MAIN, getResources().getString(R.string.index));
                break;
            default:
                // ?
                ThemesFragment themesFragment = (ThemesFragment) getSupportFragmentManager()
                        .findFragmentByTag(themeId + "");
                if (themesFragment == null) {
                    themesFragment = ThemesFragment.newInstance(themeId);
                }
                switchFragment(themesFragment, themeId + "", menuItem.getTitle().toString());
                break;

            }
            // ??
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}