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.zirconi.huaxiaclient.LoginActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_about:
        new AlertDialog.Builder(this).setTitle("About")
                .setMessage("VERSION:0.05 BETA\nJust for fun!\nAuthor:Zirconi\nMail:Geekkou@gmail.com")
                .setPositiveButton("OK", null).show();

        break;//from  ww  w .ja va2  s. co m
    }

    return true;
}

From source file:com.josecarlos.couplecounters.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.counter_delete) {
        Log.i("CC", "Entered onContextItemSelected - delete");
        final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        String counter = Utils.checkParameter(listAdapter.getItem(info.position).getCounterName());

        RequestParams params = new RequestParams();
        AsyncHttpClient client = new AsyncHttpClient();
        client.delete("http://josecarlosroman.com/counters/" + currentPartner1 + "/" + currentPartner2 + "/"
                + counter, params, new AsyncHttpResponseHandler() {

                    @Override/*from ww w.  ja  v a2 s.c om*/
                    public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                        Log.i("CC", "Entered onSuccess, counter deleted");
                        listAdapter.remove(listAdapter.getItem(info.position));

                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
                            Throwable error) {
                        Log.i("CC", "counter not deleted");
                    }

                });
    } else if (id == R.id.counter_change) {
        final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        CounterItem counterItem = listAdapter.getItem(info.position);
        if (counterItem.isCommon()) {
            Utils.setCounterType(currentPartner1, currentPartner2,
                    Utils.checkParameter(counterItem.getCounterName()), "0");
            counterItem.setCommon(false);
        } else {
            Utils.setCounterType(currentPartner1, currentPartner2,
                    Utils.checkParameter(counterItem.getCounterName()), "1");
            counterItem.setCommon(true);
        }
        listAdapter.set(info.position, counterItem);
    }
    return super.onContextItemSelected(item);
}

From source file:io.github.protino.codewatch.ui.ProfileActivity.java

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

From source file:itesm.mx.golpedecalor.SelectGroupActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int id = item.getItemId();

    // Si se elimina se llama a la funcin de eliminar en DBO
    if (id == R.id.delete) {
        //(grupos.get(info.position)).getId()

        //Toast.makeText(getApplicationContext(), "DELETE " + nombres.get(info.position), Toast.LENGTH_LONG).show();
        boolean deleted = dbo.deleteGroup((grupos.get(info.position)).getId());

        nombres.remove(info.position);/*from  w ww. j a v  a2s.co m*/
        adapter.notifyDataSetChanged();

        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:com.example.android.swiperefreshlistfragment.SwipeRefreshListFragmentFragment.java

/**
 * Respond to the user's selection of the Refresh action item. Start the SwipeRefreshLayout
 * progress bar, then initiate the background task that refreshes the content.
 *
 * <p>A color scheme menu item used for demonstrating the use of SwipeRefreshLayout's color
 * scheme functionality. This kind of menu item should not be incorporated into your app,
 * it just to demonstrate the use of color. Instead you should choose a color scheme based
 * off of your application's branding.//w w w .  jav a2 s.com
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_refresh:
        Log.i(LOG_TAG, "Refresh menu item selected");

        // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator
        if (!isRefreshing()) {
            setRefreshing(true);
        }

        // Start our refresh background task
        //                initiateRefresh();
        return true;

    case R.id.menu_color_scheme_1:
        Log.i(LOG_TAG, "setColorScheme #1");
        item.setChecked(true);

        // Change the colors displayed by the SwipeRefreshLayout by providing it with 4
        // color resource ids
        setColorScheme(R.color.color_scheme_1_1, R.color.color_scheme_1_2, R.color.color_scheme_1_3,
                R.color.color_scheme_1_4);
        return true;

    case R.id.menu_color_scheme_2:
        Log.i(LOG_TAG, "setColorScheme #2");
        item.setChecked(true);

        // Change the colors displayed by the SwipeRefreshLayout by providing it with 4
        // color resource ids
        setColorScheme(R.color.color_scheme_2_1, R.color.color_scheme_2_2, R.color.color_scheme_2_3,
                R.color.color_scheme_2_4);
        return true;

    case R.id.menu_color_scheme_3:
        Log.i(LOG_TAG, "setColorScheme #3");
        item.setChecked(true);

        // Change the colors displayed by the SwipeRefreshLayout by providing it with 4
        // color resource ids
        setColorScheme(R.color.color_scheme_3_1, R.color.color_scheme_3_2, R.color.color_scheme_3_3,
                R.color.color_scheme_3_4);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:net.idlesoft.android.apps.github.activities.SingleActivityItem.java

public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case 0://from w w  w .j a  v  a  2 s . c o m
        final Intent i1 = new Intent(this, Hubroid.class);
        startActivity(i1);
        return true;
    case 1:
        mEditor.clear().commit();
        final Intent intent = new Intent(this, Hubroid.class);
        startActivity(intent);
        return true;
    case 2:
        final File root = Environment.getExternalStorageDirectory();
        if (root.canWrite()) {
            final File hubroid = new File(root, "hubroid");
            if (!hubroid.exists() && !hubroid.isDirectory()) {
                return true;
            } else {
                hubroid.delete();
                return true;
            }
        }
    }
    return false;
}

From source file:com.example.android.apis.graphics.FingerPaint.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    mPaint.setXfermode(null);//from w  ww.  j a va 2s.  co  m
    mPaint.setAlpha(0xFF);

    switch (item.getItemId()) {
    case ERASE_ALL_ID:
        myView.getBitmap().eraseColor(Color.TRANSPARENT);
        myView.invalidate();
        return true;

    case COLOR_MENU_ID:
        new ColorPickerDialog(this, this, mPaint.getColor()).show();
        return true;
    case EMBOSS_MENU_ID:
        if (mPaint.getMaskFilter() != mEmboss) {
            mPaint.setMaskFilter(mEmboss);
        } else {
            mPaint.setMaskFilter(null);
        }
        return true;
    case BLUR_MENU_ID:
        if (mPaint.getMaskFilter() != mBlur) {
            mPaint.setMaskFilter(mBlur);
        } else {
            mPaint.setMaskFilter(null);
        }
        return true;
    case ERASE_MENU_ID:
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        return true;
    case SRCATOP_MENU_ID:
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
        mPaint.setAlpha(0x80);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.stadtrallye.rallyesoft.ConnectionAssistantActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from   ww w . j  a v a2  s.co  m*/
        return true;
    case R.id.scan_qr_login:
        IntentIntegrator zx = new IntentIntegrator(this);
        zx.initiateScan(IntentIntegrator.QR_CODE_TYPES);
        return true;
    }
    return false;
}

From source file:com.tk.httpClientErp.headmancheck.HeadmancheckDetailActivity.java

/**
 * =====================================
 *//*from   ww  w.  ja  v  a2 s  . c  om*/
@SuppressWarnings("unchecked")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    String reultString = null;
    switch (item.getItemId()) {
    case R.id.menu_item_headmanchecklist_check_yes:
        HashMap<String, Object> hashMapsYES = MyStore.subAndDel(MyStore.headManCheckList);
        List<JSONObject> submitJsonArrayYES = (List<JSONObject>) hashMapsYES.get("submitJsonArray");
        List<HashMap<String, Object>> delListYES = (List<HashMap<String, Object>>) hashMapsYES.get("delList");
        params.add(new BasicNameValuePair("submitJsonArray", submitJsonArrayYES.toString()));
        try {
            reultString = HttpClientUtil.postRequest("/android.do?method=updateHeadmancheckYES", params,
                    MyStore.sessionID);
        } catch (TimeoutException e) {
            e.printStackTrace();
            HeadmancheckDetailActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(HeadmancheckDetailActivity.this, MyStore.TIMEOUTLOGIN, Toast.LENGTH_SHORT)
                            .show();
                }
            });
        }
        reultString = HttpClientUtil.callBackSuccOrFail(reultString, "resualt");
        if (HttpClientUtil.reSUCCorFAILE && delListYES.size() != 0) {
            MyStore.headManCheckList.removeAll(delListYES);
            headmancheckDetail.removeAll(delListYES);
        }
        final String MSG = reultString;
        HeadmancheckDetailActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(HeadmancheckDetailActivity.this, MSG, Toast.LENGTH_SHORT).show();
            }
        });
        if (headmancheckDetail.size() == 0) {
            MyStore.deletBeanById(gd_no, "gd_no", MyStore.headManCheckFenzu);
            HeadmancheckDetailActivity.this.finish(); // Activity
        }
        ((MySimpleAdapter) getListAdapter()).notifyDataSetChanged();
        break;
    case R.id.menu_item_headmanchecklist_check_no:
        HashMap<String, Object> hashMapsNO = MyStore.subAndDel(MyStore.headManCheckList);
        List<JSONObject> submitJsonArrayNO = (List<JSONObject>) hashMapsNO.get("submitJsonArray");
        List<HashMap<String, Object>> delListNO = (List<HashMap<String, Object>>) hashMapsNO.get("delList");
        params.add(new BasicNameValuePair("submitJsonArray", submitJsonArrayNO.toString()));
        try {
            reultString = HttpClientUtil.postRequest("/android.do?method=updateHeadmancheckNO", params,
                    MyStore.sessionID);
        } catch (TimeoutException e) {
            e.printStackTrace();
            HeadmancheckDetailActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(HeadmancheckDetailActivity.this, MyStore.TIMEOUTLOGIN, Toast.LENGTH_SHORT)
                            .show();
                }
            });
        }
        reultString = HttpClientUtil.callBackSuccOrFail(reultString, "resualt");
        if (HttpClientUtil.reSUCCorFAILE && delListNO.size() != 0) {
            MyStore.headManCheckList.removeAll(delListNO);
            headmancheckDetail.removeAll(delListNO);
        }
        final String MSG2 = reultString;
        HeadmancheckDetailActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(HeadmancheckDetailActivity.this, MSG2, Toast.LENGTH_SHORT).show();
            }
        });
        if (headmancheckDetail.size() == 0) {
            MyStore.deletBeanById(gd_no, "gd_no", MyStore.headManCheckFenzu);
            HeadmancheckDetailActivity.this.finish(); // Activity
        }
        ((MySimpleAdapter) getListAdapter()).notifyDataSetChanged();
        break;
    case R.id.menu_item_headmanchecklist_selectec_or_cancle:
        MyStore.selectORcancle(mResult, "mResult", headmancheckDetail);
        mResult = mResult == true ? false : true;
        ((MySimpleAdapter) getListAdapter()).notifyDataSetChanged();
        break;
    }
    return true;
}

From source file:com.pansapiens.occyd.Search.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent I;/*from w w w  . j  av  a 2s.com*/
    switch (item.getItemId()) {
    case 0:
        I = new Intent(this, Search.class);
        break;
    case 1:
        I = new Intent(this, NewPost.class);
        break;
    case 2:
        // if we launch the map, leave this Search activity
        // on the history stack (ie no call of this.finish() )
        // so that the back button brings us from the map back to here
        showMapResults(searchResults_json);
        return true;
    case 3:
        startActivity(new Intent(this, Prefs.class));
        return true;
    case 4:
        //showAlert("Menu Item Clicked", "Help", "ok", null, false, null);
        return true;
    default:
        return false;
    }

    startActivity(I);
    this.finish();
    return true;
}