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:org.teleportr.activity.Autocompletion.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.about:
        startActivity(new Intent(this, About.class));
        break;//w  w  w  .  j a va2  s.  co m

    case R.id.refresh:
        new FetchNearbyDownloads().execute("");
        break;

    case R.id.feedback:
        new AlertDialog.Builder(this).setTitle("feedback").setIcon(android.R.drawable.ic_dialog_info)
                .setPositiveButton("send logs", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        LogCollector.feedback(Autocompletion.this, "scotty@teleportr.org, flo@andlabs.de");
                    }
                }).setNeutralButton("mail scotty", new Dialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_SENDTO,
                                Uri.parse("mailto:scotty@teleportr.org, flo@andlabs.de"));
                        intent.putExtra(Intent.EXTRA_SUBJECT, "feedback " + getString(R.string.app_name));
                        try {
                            PackageInfo info = getPackageManager().getPackageInfo("org.teleportr",
                                    PackageManager.GET_META_DATA);
                            intent.putExtra(Intent.EXTRA_TEXT,
                                    "version: " + info.versionName + " (" + info.versionCode + ") \n");
                        } catch (NameNotFoundException e) {
                        }
                        startActivity(intent);
                    }
                }).show();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.starwood.anglerslong.LicenseAddActivity.java

/*********************************************************
 * Gives functionality to the action bar
 *********************************************************/
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.save:
        try {/*from   w ww .  jav  a 2s  .  co m*/
            readLicense(isPopulated, isArrayEmpty);

            if (!hasEmptyField)
                onBackPressed();
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "**Error** Your item was not saved.", Toast.LENGTH_SHORT)
                    .show();
            e.printStackTrace();
        }
        return true;

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

From source file:com.vmihalachi.turboeditor.fragment.NavigationDrawerListFragment.java

/**
 * {@inheritDoc}/*from w  w w.ja v  a2 s.  c  o m*/
 */
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.im_remove:
        // File paths saved in preferences
        String[] savedPaths = PreferenceHelper.getSavedPaths(getActivity());
        // We get the checked positions
        SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
        // If we have some checked positions
        if (checkedItems != null) {
            for (int i = 0; i < checkedItems.size(); i++) {
                // check if the value is checked
                if (checkedItems.valueAt(i)) {
                    // remove the checked path, but don't refresh the list
                    removePath(savedPaths[checkedItems.keyAt(i)], false);
                }
            }
            // In the end refresh the list
            refreshList();
        }
        // Close the action mode
        actionMode.finish();
        return true;
    default:
        return false;
    }
}

From source file:net.eledge.android.europeana.gui.activity.HomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings:
        Intent i = new Intent(this, SettingsActivity.class);
        startActivityForResult(i, 1);/* ww w . j  a  v  a 2  s.  c om*/
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.LockActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_settings) {
        Intent intent = new Intent();
        intent.setClass(LockActivity.this, AdvancedPreferenceActivity.class);
        startActivityForResult(intent, 0);
        return true;
    } else if (id == R.id.action_reset) {
        PreferenceManager.getDefaultSharedPreferences(this).edit().clear().apply(); //reset
        PreferenceManager.setDefaultValues(this, R.xml.advanced, true);
        return true;
    } else if (id == R.id.action_quit) {
        Intent i = new Intent(this, RviService.class);
        stopService(i);/* w ww. j  a  v  a 2  s  .c om*/
        finish();
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.mifos.mifosxdroid.online.ClientChargeFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == MENU_ITEM_ADD_NEW_CHARGES) {
        ChargeDialogFragment chargeDialogFragment = ChargeDialogFragment.newInstance(clientId);
        FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
        fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CHARGE_LIST);
        chargeDialogFragment.show(fragmentTransaction, "Charge Dialog Fragment");
    }//from  w ww .ja va 2s  .c  o  m

    return super.onOptionsItemSelected(item);
}

From source file:edu.stanford.mobisocial.dungbeetle.ImageViewerActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case SAVE: {/*from w  w  w . ja  v a  2  s  . c o m*/
        OutputStream outStream = null;
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
        Date date = new Date();
        File file = new File(extStorageDirectory, dateFormat.format(date) + ".PNG");
        File fileDirectory = new File(extStorageDirectory);
        fileDirectory.mkdirs();
        try {
            outStream = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();

            Toast.makeText(ImageViewerActivity.this, "Saved", Toast.LENGTH_LONG).show();

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(ImageViewerActivity.this, e.toString(), Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(ImageViewerActivity.this, e.toString(), Toast.LENGTH_LONG).show();
        }
        return true;
    }
    case SET_PROFILE: {
        if (mIntent.hasExtra("b64Bytes")) {
            String b64Bytes = mIntent.getStringExtra("b64Bytes");
            byte[] data = FastBase64.decode(b64Bytes);
            Helpers.updatePicture(ImageViewerActivity.this, data);
            Toast.makeText(ImageViewerActivity.this, "Set profile picture.", Toast.LENGTH_LONG).show();

        } else {
            Toast.makeText(ImageViewerActivity.this, "Error setting profile picture.", Toast.LENGTH_LONG)
                    .show();
        }
        return true;
    }
    default:
        return false;
    }
}

From source file:fr.cph.stock.android.activity.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    MainTask mainTask;/*w  w  w  . j  a v  a2 s.  c o  m*/
    switch (item.getItemId()) {
    case R.id.action_logout:
        mainTask = new MainTask(this, UrlType.LOGOUT, null);
        mainTask.execute((Void) null);
        return true;
    case R.id.refresh:
        menuItem = item;
        menuItem.setActionView(R.layout.progressbar);
        menuItem.expandActionView();
        tracker.sendEvent("Buttons Category", "Reload", "", 0L);
        mainTask = new MainTask(this, UrlType.RELOAD, null);
        mainTask.execute((Void) null);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.bonsai.wallet32.PairWalletActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    Intent intent;//from w w w. j a  va2s .com
    switch (item.getItemId()) {
    case R.id.action_about:
        intent = new Intent(this, AboutActivity.class);
        startActivity(intent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:in.andres.kandroid.ui.LoginActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        onBackPressed();/*from w  ww  .  j ava  2  s.c o  m*/
        return true;
    }
    return super.onOptionsItemSelected(item);
}