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:Main.java

public static boolean defaultOnOptionsItemSelected(Activity activity, MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        activity.onBackPressed();//  ww w. ja  va  2 s  .  com
        return true;
    default:
        return false;
    }
}

From source file:Main.java

public static View getMenuItemView(Activity activity, MenuItem item) {
    return activity.findViewById(item.getItemId());
}

From source file:Main.java

public static void removeCurItem(MenuItem item, int idx, ViewPager vp) {
    for (int i = 0; i < vp.getAdapter().getCount(); i++) {
        if (item.getItemId() == idx + i + 1) {
            vp.setCurrentItem(i);/*from  ww  w . ja v  a  2s  . c  o m*/
        }
    }
}

From source file:com.wms.opensource.images3android.manager.MenuManager.java

public static void displayImageProcessOptionsMenu(final Context context, final Image image, final Bitmap bitmap,
        final ReviewImageManager manager) {
    IconContextMenu cm = new IconContextMenu(context, R.menu.image_process_options_menu);
    cm.setOnIconContextItemSelectedListener(new IconContextItemSelectedListener() {

        @SuppressWarnings("deprecation")
        @Override/*from  w  w w .ja  v  a2s.  c  om*/
        public void onIconContextItemSelected(MenuItem item, Object info) {
            if (item.getItemId() == R.id.action_hint) {
                // Position 0 is the indication for selecting a template, so we do nothing
            } else if (item.getItemId() == R.id.action_save_to_gallery) {
                MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, image.getId(), "");
                Toast.makeText(context, context.getString(R.string.saveToGallaryCompleted), Toast.LENGTH_LONG)
                        .show();
            } else if (item.getItemId() == R.id.action_set_as_wall_paper) {
                try {
                    context.setWallpaper(bitmap);
                    Toast.makeText(context, context.getString(R.string.setWallPaperCompleted),
                            Toast.LENGTH_LONG).show();
                } catch (IOException e) {

                }
            } else if (item.getItemId() == R.id.action_delete) {
                manager.dismiss();
                // Delete image
                DeleteImageTask task = new DeleteImageTask(context, image.getBaseUrl(), image.getImagePlantId(),
                        image.getId());
                task.execute();
            }
        }
    });

    cm.show();
}

From source file:com.wms.opensource.images3android.manager.MenuManager.java

public static void displayTemplatesMenu(final Context context, final Image image) {
    IconContextMenu cm = new IconContextMenu(context, R.menu.templates_menu);
    if (templateCollection == null) {
        String templateCollectionString = "";
        templateCollectionString = FileUtil.getStringFromFileInCache(StorageUtil.getTempDirectory(context),
                PersistFileNameUtil.getTemplateCollectionFileName(image.getImagePlantId()),
                context.getString(R.string.charSetName));
        try {//w  w  w.  j a v  a 2s  .c o  m
            templateCollection = (TemplateCollection) JsonUtil.deserialize(templateCollectionString, "",
                    TemplateCollection.class);
        } catch (JsonParseException e) {

        } catch (JsonMappingException e) {

        } catch (IOException e) {

        }
    }
    for (int i = 0; i < templateCollection.getResults().size(); i++) {
        TemplateResult result = templateCollection.getResults().get(i);
        cm.getMenu().add(0, i + 1, i, result.getId().getTemplateName());
    }

    cm.setOnIconContextItemSelectedListener(new IconContextItemSelectedListener() {
        @Override
        public void onIconContextItemSelected(MenuItem item, Object info) {
            if (item.getItemId() == R.id.action_hint) {
                // Position 0 is the indication for selecting a template, so we do nothing
            } else {
                String templateName = item.getTitle().toString();
                ReviewImageManager reviewImageManager = new ReviewImageManager(context);
                reviewImageManager.showImagePopupWindow(image, templateName);
            }
        }
    });

    cm.show();
}

From source file:com.arantius.tivocommander.Utils.java

public final static boolean onOptionsItemSelected(MenuItem item, Activity srcActivity, boolean homeIsBack) {
    if (android.R.id.home == item.getItemId() && homeIsBack) {
        srcActivity.finish();//  w ww . j av  a 2s  . c  o m
        return true;
    }

    Class<? extends Activity> targetActivity = Utils.activityForMenuId(item.getItemId());
    if (targetActivity == null) {
        Utils.logError("Unknown menu item ID: " + Integer.toString(item.getItemId()));
        return false;
    }
    Intent intent = new Intent(srcActivity, targetActivity);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    srcActivity.startActivity(intent);
    return true;
}

From source file:com.ruenzuo.pokeffective.activities.InfoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        finishAnimated();//w w w . j  ava2 s . c o m
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:SplashActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }//from w w w. j  av  a  2s .c o  m
    return super.onOptionsItemSelected(item);
}

From source file:MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_DOWNLOAD:
        Toast.makeText(this, R.string.menu_download, Toast.LENGTH_LONG).show();
        break;//from   w ww.  j  a v a 2  s .c o  m
    case MENU_SETTINGS:
        Toast.makeText(this, R.string.menu_settings, Toast.LENGTH_LONG).show();
        break;
    default:
        return super.onContextItemSelected(item);
    }
    return true;
}

From source file:com.android.mail.ui.LicensesActivity.java

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