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.codebutler.farebot.activities.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    try {/*from ww  w  . j ava  2s  . com*/
        if (item.getItemId() == R.id.supported_cards) {
            startActivity(new Intent(this, SupportedCardsActivity.class));
            return true;

        } else if (item.getItemId() == R.id.about) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://codebutler.github.com/farebot")));
            return true;

        } else if (item.getItemId() == R.id.import_clipboard) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            onCardsImported(ExportHelper.importCardsXml(this, clipboard.getText().toString()));
            return true;

        } else if (item.getItemId() == R.id.import_file) {
            Uri uri = Uri.fromFile(Environment.getExternalStorageDirectory());
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.putExtra(Intent.EXTRA_STREAM, uri);
            i.setType("application/xml");
            startActivityForResult(Intent.createChooser(i, "Select File"), SELECT_FILE);
            return true;

        } else if (item.getItemId() == R.id.import_sd) {
            String xml = FileUtils.readFileToString(new File(SD_EXPORT_PATH));
            onCardsImported(ExportHelper.importCardsXml(this, xml));
            return true;

        } else if (item.getItemId() == R.id.copy_xml) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(ExportHelper.exportCardsXml(this));
            Toast.makeText(this, "Copied to clipboard.", 5).show();
            return true;

        } else if (item.getItemId() == R.id.share_xml) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, ExportHelper.exportCardsXml(this));
            startActivity(intent);
            return true;

        } else if (item.getItemId() == R.id.save_xml) {
            String xml = ExportHelper.exportCardsXml(this);
            File file = new File(SD_EXPORT_PATH);
            FileUtils.writeStringToFile(file, xml, "UTF-8");
            Toast.makeText(this, "Wrote FareBot-Export.xml to USB Storage.", 5).show();
            return true;

        } else if (item.getItemId() == R.id.prefs) {
            startActivity(new Intent(this, FareBotPreferenceActivity.class));
        }
    } catch (Exception ex) {
        Utils.showError(this, ex);
    }
    return false;
}

From source file:com.example.android.sunshine.fragments.ForecastFragment.java

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

    if (id == R.id.action_refresh) {
        updateWeather();//from   w w  w.ja  v a 2 s.c  o  m
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.mohammedsazidalrashid.android.sunshine.ForecastFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_refresh) {
        //            updateWeather();
        mSwipeRefreshLayout.post(new Runnable() {
            @Override//from w ww.  j a v a 2  s . co  m
            public void run() {
                updateWeather();
                mSwipeRefreshLayout.setRefreshing(true);
            }
        });
        Toast.makeText(getActivity(), "TIP: Swipe down to refresh :)", Toast.LENGTH_SHORT).show();
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.project.binbinfu.the_city.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This is called when the Home (Up) button is pressed in the action bar.
        // Create a simple intent that starts the hierarchical parent activity and
        // use NavUtils in the Support Package to ensure proper handling of Up.
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();/*from   w  w  w .j  av  a2  s.c om*/
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.sakisds.icymonitor.fragments.NotificationsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.item_test_notification:
        AsyncHttpClient client = new AsyncHttpClient();

        String url = getActivity().getIntent().getStringExtra(MainViewActivity.EXTRA_ADDRESS) + "/data";
        RequestParams params = new RequestParams();
        params.put("type", "testnotif");
        params.put("id", String.valueOf(mSettings.getLong("device_id", -2)));

        client.get(url, params, new TextHttpResponseHandler() {
            @Override//w  w w.ja  va2  s . co  m
            public void onSuccess(int statusCode, Header[] headers, String responseBody) {
                Toast.makeText(getActivity(), "Test notification sent", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailure(String responseBody, Throwable error) {
                Toast.makeText(getActivity(), "Test notification could not be sent: " + error.getMessage(),
                        Toast.LENGTH_LONG).show();
            }
        });

        return true;
    case R.id.item_add:
        Intent intent = new Intent(getActivity(), AddNotificationActivity.class);
        intent.putExtra(MainViewActivity.EXTRA_ADDRESS,
                getActivity().getIntent().getStringExtra(MainViewActivity.EXTRA_ADDRESS) + "/data");

        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.scigames.slidegame.Registration1UserNameActivity.java

/**
 * Called when a menu item is selected.//w  w w .  j  a v  a2 s .c o m
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case BACK_ID:
        finish();
        return true;
    case CLEAR_ID:
        lastName.setText("");
        firstName.setText("");
        password.setText("");
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.onesignal.example.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();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings)
        return true;

    return super.onOptionsItemSelected(item);
}

From source file:com.zion.htf.ui.DonateActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean ret = true;

    switch (item.getItemId()) {
    case android.R.id.home:
        this.finish();
        break;/*from w  w  w.  j  a v  a 2  s . c  o m*/

    default:
        ret = false;
    }

    return ret;
}

From source file:com.grupohqh.carservices.operator.ShowCarActivity.java

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

    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    case R.id.action_refresh_car:
        new LoadCarAsyncTask().execute(CAR_URL);
        return true;
    }// ww  w  .  j a  va 2  s  . c  o  m

    return super.onOptionsItemSelected(item);
}

From source file:net.networksaremadeofstring.rhybudd.DiagnosticActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        finish();//w  w  w.  j  a  va2  s. c  o m
        return true;
    }

    default: {
        return false;
    }
    }
}