Example usage for android.view MenuItem getItemId

List of usage examples for android.view MenuItem getItemId

Introduction

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

Prototype

public int getItemId();

Source Link

Document

Return the identifier for this menu item.

Usage

From source file:com.dodo.wbbshoutbox.codebot.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.login:
        Intent myIntent = new Intent(getApplicationContext(), Login.class);
        startActivityForResult(myIntent, 0);
        return true;
    case R.id.settings:
        Intent myIntent2 = new Intent(getApplicationContext(), Settings2.class);
        startActivityForResult(myIntent2, 0);
        return true;
    case R.id.logout:
        logout();/*w  ww.  ja  v a 2s .  c o  m*/
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.example.okano.simpleroutesearch.MapsActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_A:/*from w w w. j  a va 2 s. c om*/
        showMapInfo();
        //show_mapInfo();
        return true;

    case MENU_B:
        //Legal Notices(?)

        String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
        AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MapsActivity.this);
        LicenseDialog.setTitle("Legal Notices");
        LicenseDialog.setMessage(LicenseInfo);
        LicenseDialog.show();

        return true;

    case MENU_c:
        //show_settings();
        return true;

    }
    return false;
}

From source file:com.scrachx.foodfacts.checker.ui.main.MainActivity.java

void setupNavMenu() {
    View headerLayout = mNavigationView.getHeaderView(0);
    mProfileImageView = (RoundedImageView) headerLayout.findViewById(R.id.iv_profile_pic);
    mNameTextView = (TextView) headerLayout.findViewById(R.id.tv_name);
    mEmailTextView = (TextView) headerLayout.findViewById(R.id.tv_email);

    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override// www.ja va2 s .  c  o m
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            mDrawer.closeDrawer(GravityCompat.START);
            switch (item.getItemId()) {
            case R.id.nav_item_search:
                mPresenter.onDrawerOptionSearchClick();
                return true;
            case R.id.nav_item_history:
                mPresenter.onDrawerOptionHistoryClick();
                return true;
            case R.id.nav_item_allergens:
                mPresenter.onDrawerOptionAllergensClick();
                return true;
            case R.id.nav_item_scan:
                mPresenter.onDrawerOptionScanClick();
                return true;
            case R.id.nav_item_about:
                mPresenter.onDrawerOptionAboutClick();
                return true;
            case R.id.nav_item_logout:
                mPresenter.onDrawerOptionLogoutClick();
                return true;
            default:
                return false;
            }
        }
    });
}

From source file:net.kourlas.voipms_sms.activities.ConversationsActivity.java

/**
 * Called when an action mode item is clicked.
 *
 * @param mode The action mode containing the item that is clicked.
 * @param item The item that is clicked.
 * @return Returns true if the method handles the item clicked.
 *//*w  ww .  ja  va2s.c  o m*/
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
    case R.id.mark_read_unread_button:
        for (int i = 0; i < adapter.getItemCount(); i++) {
            if (adapter.isItemChecked(i)) {
                Message[] smses = adapter.getItem(i).getMessages();
                for (Message message : smses) {
                    message.setUnread(item.getTitle()
                            .equals(getResources().getString(R.string.conversations_action_mark_unread)));
                    database.insertMessage(message);
                }
            }
        }
        adapter.refresh();
        mode.finish();
        return true;
    case R.id.delete_button:
        List<Long> databaseIds = new ArrayList<>();
        for (int i = 0; i < adapter.getItemCount(); i++) {
            if (adapter.isItemChecked(i)) {
                for (Message message : adapter.getItem(i).getMessages()) {
                    if (message.getDatabaseId() != null) {
                        databaseIds.add(message.getDatabaseId());
                    }
                }
            }
        }

        Long[] databaseIdsArray = new Long[databaseIds.size()];
        databaseIds.toArray(databaseIdsArray);
        deleteMessages(databaseIdsArray);
        mode.finish();
        return true;
    default:
        return false;
    }
}

From source file:com.mobshep.shepherdlogin.MainActivity.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();

    switch (id) {

    case R.id.action_settings:

        Intent goToSettings = new Intent(this, Preferences.class);
        startActivity(goToSettings);//from w ww. ja  v a  2 s.  c  o m
        return true;

    case R.id.action_clearSession:

        storedPref = getSharedPreferences("Sessions", MODE_PRIVATE);
        toEdit = storedPref.edit();
        toEdit.clear();
        toEdit.commit();

        //delete * from sessions table
        SessionProvider.DatabaseHelper providerInstance;
        providerInstance = new SessionProvider.DatabaseHelper(this);
        providerInstance.deleteData();

        Toast valid = Toast.makeText(MainActivity.this, "Sessions cleared!", Toast.LENGTH_SHORT);
        valid.show();

    case R.id.action_exit:

        this.finish();

        break;

    default:

    }
    return super.onOptionsItemSelected(item);

}

From source file:com.maskyn.fileeditorpro.activity.SelectFileActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int i = item.getItemId();
    if (i == android.R.id.home) {
        finish();/*from   w w w. j  a  v a  2 s. c  om*/
        return true;
    } else if (i == R.id.im_set_as_working_folder) {
        PreferenceHelper.setWorkingFolder(SelectFileActivity.this, currentFolder);
        invalidateOptionsMenu();
        return true;
    } else if (i == R.id.im_is_working_folder) {
        Toast.makeText(getBaseContext(), R.string.is_the_working_folder, Toast.LENGTH_SHORT).show();
        return true;
    } else if (i == R.id.im_select_folder) {
        finishWithResult(new File(currentFolder));
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.fsa.en.dron.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    RateThisApp.Config config = new RateThisApp.Config(5, 10);
    config.setTitle(R.string.my_own_title);
    config.setMessage(R.string.my_own_message);
    config.setYesButtonText(R.string.my_own_rate);
    config.setNoButtonText(R.string.my_own_thanks);
    config.setCancelButtonText(R.string.my_own_cancel);
    RateThisApp.init(config);/*from  ww w  . ja  va 2  s  .  c o  m*/
    RateThisApp.setCallback(new RateThisApp.Callback() {
        @Override
        public void onYesClicked() {
            final String appPackageName = getPackageName(); // getPackageName() from Context or Activity  object
            try {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
            }
        }

        @Override
        public void onNoClicked() {
            TastyToast.makeText(getApplicationContext(), "Vuelve pronto!", TastyToast.LENGTH_LONG,
                    TastyToast.INFO);
        }

        @Override
        public void onCancelClicked() {
            TastyToast.makeText(getApplicationContext(), "Prometo tomar mejores fotografias!",
                    TastyToast.LENGTH_LONG, TastyToast.ERROR);
        }
    });
    button = (Button) findViewById(R.id.button);
    button.setVisibility(View.INVISIBLE);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkConnection();
        }
    });
    BottomNavigationBar bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);
    bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
    bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC);
    bottomNavigationBar.setBarBackgroundColor(R.color.material_light_blue_800);
    bottomNavigationBar.setActiveColor(R.color.material_grey_900);
    bottomNavigationBar.setInActiveColor(R.color.material_blue_grey_200);
    bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.compose, "Mensaje"))
            .addItem(new BottomNavigationItem(R.drawable.sociales, "Sociales"))
            .addItem(new BottomNavigationItem(R.drawable.share, "Cuntale a un amigo")).initialise();
    bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
        @Override
        public void onTabSelected(int position) {
            switch (position) {
            case 0:
                Intent email = new Intent(Intent.ACTION_SEND);
                email.putExtra(Intent.EXTRA_EMAIL, new String[] { "marceloespinoza00@gmail.com" });
                email.putExtra(Intent.EXTRA_SUBJECT, "Formosa en dron");
                email.putExtra(Intent.EXTRA_TEXT, "Dej tu mensaje");
                email.setType("message/rfc822");
                startActivity(Intent.createChooser(email, "Elige un cliente :"));
                break;
            case 1:
                Intent intent = new Intent(getApplication(), FacebookActivity.class);
                startActivity(intent);
                break;
            case 2:

                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Formosa en dron");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                        "https://play.google.com/store/apps/details?id=com.fsa.en.dron");
                startActivity(Intent.createChooser(sharingIntent, "Compartir via"));
                break;

            }

        }

        @Override
        public void onTabUnselected(int position) {

        }

        @Override
        public void onTabReselected(int position) {
            switch (position) {
            case 0:

                break;
            case 1:
                Intent intent = new Intent(getApplication(), FacebookActivity.class);
                startActivity(intent);
                break;
            case 2:

                break;

            }
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    LayoutInflater inflator = LayoutInflater.from(this);
    View v = inflator.inflate(R.layout.toolbar_title, null);
    Typeface budget = Typeface.createFromAsset(getAssets(), "fonts/Budget.otf");
    Typeface typographica = Typeface.createFromAsset(getAssets(), "fonts/TypoGraphica.otf");
    TextView mToolbarCustomTitle = (TextView) v.findViewById(R.id.title);
    TextView mToolbarCustomSubTitle = (TextView) v.findViewById(R.id.subtitle);
    mToolbarCustomTitle.setText("Formosa");
    mToolbarCustomSubTitle.setText("en dron");
    mToolbarCustomTitle.setTypeface(typographica);
    mToolbarCustomSubTitle.setTypeface(budget);
    getSupportActionBar().setCustomView(v);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.recargar) {
                checkConnection();
            }
            if (id == R.id.info) {
                showDialog();
            }
            return false;
        }
    });
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.addOnItemTouchListener(new GalleryAdapter.RecyclerTouchListener(getApplicationContext(),
            recyclerView, new GalleryAdapter.ClickListener() {
                @Override
                public void onClick(View view, int position) {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("images", images);
                    bundle.putInt("position", position);

                    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                    SlideshowDialogFragment newFragment = SlideshowDialogFragment.newInstance();
                    newFragment.setArguments(bundle);
                    newFragment.show(ft, "slideshow");
                }

                @Override
                public void onLongClick(View view, int position) {

                }
            }));
    pDialog = new ProgressDialog(this);
    images = new ArrayList<>();
    mAdapter = new GalleryAdapter(getApplicationContext(), images);
    RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);

}

From source file:com.richtodd.android.quiltdesign.app.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case R.id.menu_settings: {
        Intent intent = new Intent(this, MainPreferenceActivity.class);
        startActivity(intent);//from   w w  w  .j  av  a 2 s.  c om

        return true;
    }
    case R.id.menu_about: {
        TextDialogFragment dialog = TextDialogFragment.create("About Quilt Design", getString(R.string.about),
                "Close");
        dialog.show(getFragmentManager(), null);

        return true;
    }
    case R.id.menu_help: {
        // Intent intent = new Intent(this, BrowserActivity.class);
        // intent.putExtra(BrowserActivity.ARG_URL,
        // "http://quiltdesign.richtodd.com");

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://quiltdesign.richtodd.com"));
        startActivity(intent);

        return true;
    }
    case R.id.menu_backup: {
        Uri uriFile;
        try {
            uriFile = saveRepository();

            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_STREAM, uriFile);
            intent.setType("application/vnd.richtodd.quiltdesign");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            startActivity(Intent.createChooser(intent, "Backup"));

        } catch (RepositoryException e) {
            Handle.asRuntimeError(e);
        }

        return true;
    }
    case R.id.menu_loadSamples: {

        SampleLoaderTask task = new SampleLoaderTask();
        setSampleLoaderTask(task);
        task.execute(this);

        return true;
    }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.richtodd.android.quiltdesign.app.QuiltEditActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case android.R.id.home: {
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }/*w  w  w  .  j  a  v  a  2  s. c o  m*/
    case R.id.menu_quiltOptions: {
        Quilt quilt = getQuiltEditFragment().getQuilt();
        QuiltOptionsDialogFragment dialog = QuiltOptionsDialogFragment.create(quilt.getRowCount(),
                quilt.getColumnCount(), (int) quilt.getWidth());
        dialog.show(getFragmentManager(), null);
        return true;
    }
    case R.id.menu_shareQuilt: {
        ShareOptionsDialogFragment dialog = ShareOptionsDialogFragment.create(Intent.ACTION_SEND);
        dialog.show(getFragmentManager(), null);
        return true;
    }
    case R.id.menu_viewQuilt: {
        ShareOptionsDialogFragment dialog = ShareOptionsDialogFragment.create(Intent.ACTION_VIEW);
        dialog.show(getFragmentManager(), null);
        return true;
    }
    case R.id.menu_renameQuilt: {
        showEditNameDialog();
        return true;
    }
    case R.id.menu_deleteQuilt: {
        AlertDialogFragment dialog = AlertDialogFragment.create(KEY_CONFIRM_DELETE,
                getString(R.string.alert_message_confirmQuiltDelete), getString(R.string.alert_button_yes),
                getString(R.string.alert_button_no));
        dialog.show(getFragmentManager(), null);
        return true;
    }
    case R.id.menu_cancelChanges: {
        getQuiltEditFragment().setSaveSuppressed(true);
        finish();
        return true;
    }
    case R.id.menu_settings: {
        Intent intent = new Intent(this, QuiltPreferenceActivity.class);
        startActivity(intent);
        return true;
    }
    }

    return super.onOptionsItemSelected(item);
}

From source file:fr.bde_eseo.eseomega.events.tickets.PresalesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    // Handle action bar actions click
    switch (item.getItemId()) {
    case android.R.id.home:
        this.onBackPressed();
        return true;

    default:/*  w  w  w . j a v a  2 s.  c o  m*/
        return super.onOptionsItemSelected(item);
    }
}