Example usage for android.view Menu addSubMenu

List of usage examples for android.view Menu addSubMenu

Introduction

In this page you can find the example usage for android.view Menu addSubMenu.

Prototype

SubMenu addSubMenu(@StringRes final int titleRes);

Source Link

Document

Add a new sub-menu to the menu.

Usage

From source file:Main.java

static public boolean doCreateOptionsMenu(Menu menu) {
    menu.add(0, MENU_KEYBOARD_SPECIAL, 0, "Special Keys");

    menu.add(0, MENU_FIT, 0, "Resize");
    SubMenu inputModeMenu = menu.addSubMenu("Input Mode");
    inputModeMenu.add(1, MENU_INPUT_MOUSE, 0, "Trackpad").setChecked(true);
    inputModeMenu.add(1, MENU_INPUT_JOYSTICK, 0, "Joystick");
    inputModeMenu.add(1, MENU_INPUT_SCROLL, 0, "Scroll Screen");
    inputModeMenu.setGroupCheckable(1, true, true);

    inputModeMenu.add(0, MENU_INPUT_SWAP_JOYPORT, 0, "Swap Joystick Ports");

    inputModeMenu.add(0, MENU_INPUT_HARDKEY, 0, "Vol. Up/Down as button").setCheckable(true);
    inputModeMenu.add(0, MENU_INPUT_USE_LEFT_ALT, 0, "Map Left-Alt Key").setCheckable(true);
    inputModeMenu.add(0, MENU_INPUT_TAP_CLICK, 0, "Tap Screen as click").setCheckable(true);
    inputModeMenu.add(0, MENU_INPUT_INPUT_METHOD, 0, "Input Method");
    inputModeMenu.add(0, MENU_INPUT_FORCE_KEYBOARD, 0, "Show Keyboard Fix").setCheckable(true);
    inputModeMenu.add(0, MENU_INPUT_KEYUP_DELAY, 0, "Keypress Fix").setCheckable(true);

    SubMenu buttonMenu = menu.addSubMenu("Buttons");
    buttonMenu.add(1, MENU_BUTTON_HIDE, 0, "Hide Buttons");
    buttonMenu.add(1, MENU_BUTTON_SHOW, 0, "Show Buttons (Slower)").setChecked(true);
    buttonMenu.add(1, MENU_BUTTON_OFF, 0, "Disable Buttons");
    buttonMenu.setGroupCheckable(1, true, true);
    buttonMenu.add(0, MENU_BUTTON_ALWAYS_SHOW_JOYSTICK, 0, "Always Show Joystick").setCheckable(true);
    buttonMenu.add(0, MENU_BUTTON_LARGE_JOYSTICK, 0, "Large Joystick").setCheckable(true);

    SubMenu settingMenu = menu.addSubMenu("Settings");
    settingMenu.add(0, MENU_SETTINGS_FRAMESKIP, 0, "Frameskip");
    settingMenu.add(0, MENU_SETTINGS_BETTER_VIDEO, 0, "Better Video").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_SHOW_INFO, 0, "Show Info").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_TRUE_DRIVE, 0, "True Drive Emulation").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_SCALE_FILTER, 0, "Smooth Resize (Slower)").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_SCALE_FACTOR, 0, "Resize Mode");
    settingMenu.add(0, MENU_SETTINGS_FAST_MOUSE, 0, "Better Mouse (Slower)").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_MOUSE_SENSITIVITY, 0, "Mouse Sensitivity");
    settingMenu.add(0, MENU_SETTINGS_JOYKEY_SET, 0, "Joystick Keys");
    settingMenu.add(0, MENU_SETTINGS_KEY_MAPPER, 0, "Button Mapper");
    settingMenu.add(0, MENU_SETTINGS_HELP, 0, "Help");
    settingMenu.add(0, MENU_SETTINGS_LICENSE, 0, "Save license to /sdcard/gpl.txt");

    menu.add(0, MENU_KEYBOARD, 0, "Keyboard");
    return true;//w  w  w. j a  v  a2 s . com
}

From source file:com.evvsoft.treeview.demo.DemoActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    SubMenu sub = menu.addSubMenu("Theme");
    sub.add(0, R.style.Theme_TreeView_Light, 0, "Light");
    sub.add(0, R.style.Theme_TreeView_Dark, 0, "Dark");
    sub.add(0, R.drawable.expander_custom_group_holo_light, 0, "Custom group indicator");
    sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    return true;//from  w w  w .j  ava  2  s  .com
}

From source file:com.josecalles.tistiq.mvp.view.MainActivity.java

private void setUpToolbarAndDrawer() {
    //mToolbar.setTitle("");
    setSupportActionBar(mToolbar);//ww w .j  av a2s.  c  o  m
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
    actionBar.setDisplayHomeAsUpEnabled(true);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open,
            R.string.drawer_close);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    setupDrawerContent(mNavigationView);
    Menu mNavMenu = mNavigationView.getMenu();
    submenu = mNavMenu.addSubMenu(R.string.individual_header);
}

From source file:com.landenlabs.all_devtool.ScreenFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.screen_menu, menu.addSubMenu("Screen Options"));
}

From source file:nyc.c4q.jordansmith.finefree.ActivityMain.java

public void addCarstoNav() {
    final Menu menu = navDrawerView.getMenu();
    if (submenu == null) {
        submenu = menu.addSubMenu("Your Cars");
        for (int i = 0; i < cars.size(); i++) {
            submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString())
                    .setIcon(R.drawable.ic_car_black_36dp);

            System.out.println(submenu.getItem(i).getItemId() + " " + submenu.getItem(i).getTitle());

            final MenuItem item = submenu.getItem(i);
            Button button = new Button(this);
            button.setText("Remove");
            button.setTextColor(ContextCompat.getColor(this, R.color.white));
            item.setActionView(button);/*w ww .  j a  v  a  2s .c  o  m*/
            button.setBackground(getDrawable(R.drawable.button_shape));
            item.getActionView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    new AlertDialog.Builder(ActivityMain.this).setIcon(android.R.drawable.ic_dialog_alert)
                            .setTitle("Delete Car").setMessage("Are you sure you want to remove car?")
                            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    System.out.println("CLICKED " + item.getTitle());
                                    cupboard().withDatabase(db).delete(Car.class, "name = ?",
                                            (String) item.getTitle());

                                    updateSubmenu();
                                }
                            }).setNegativeButton("Cancel", null).show();

                }
            });
        }
    } else {
        //            for (int i = 0; i < cars.size(); i++) {
        //                submenu.clear();
        //                submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString())
        //                        .setIcon(R.drawable.ic_car_black_36dp);
        //
        //                final MenuItem item = submenu.getItem(i);
        //                Button button = new Button(this);
        //                button.setText("Remove");
        //                item.setActionView(button);
        //                item.getActionView().setOnClickListener(new View.OnClickListener() {
        //                    @Override
        //                    public void onClick(View view) {
        //
        //                        System.out.println("CLICKED " + item.getTitle());
        //                        cupboard().withDatabase(db).delete(Car.class, "name = ?", (String) item.getTitle());
        //
        //                        updateSubmenu();
        //                    }
        //                });
        //
        //            }
        setupCarMenu();

    }
}

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.fragments.VPCompaniesFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem searchBtn = menu.findItem(R.id.action_search);
    searchBtn.setVisible(true);//from www  . j ava 2s.com

    SubMenu selectionMenu = menu.addSubMenu(getResources().getString(R.string.selection_options_btn));
    selectionMenu.getItem().setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_edit)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    selectionMenu.getItem().setTitle(getResources().getString(R.string.selection_options_btn));
    selectionMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    MenuItem selectAllItem = selectionMenu.add(getResources().getString(R.string.btn_select_all));
    selectAllItem.setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_check_square_o)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    selectAllItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    selectAllItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getActivity(), "Selected all items", Toast.LENGTH_SHORT).show();

            try {
                DBManager.setFilteredCompaniesSelected(true);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            ((CompaniesCellAdapter) recyclerView.getAdapter()).refreshData();

            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            return true;
        }
    });

    MenuItem deselectAllItem = selectionMenu.add(getResources().getString(R.string.btn_deselect_all));
    deselectAllItem.setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_square_o)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    deselectAllItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    deselectAllItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getActivity(), "Deselected all items", Toast.LENGTH_SHORT).show();

            try {
                DBManager.setFilteredCompaniesSelected(false);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            ((CompaniesCellAdapter) recyclerView.getAdapter()).refreshData();

            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            return true;
        }
    });
}

From source file:com.landenlabs.all_UiDemo.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    SubMenu pageMenu = menu.addSubMenu("Pages...");
    int groupId = 1;
    int itemId = 100;
    for (PageItem item : mItems) {
        pageMenu.add(groupId, itemId, itemId, item.mTitle);
        itemId++;/*from w w w  . j a v  a 2s  . com*/
    }
    return true;
}

From source file:org.bienvenidoainternet.app.MainActivity.java

private void getBoardList() {
    Menu menu = navigationView.getMenu();
    final SubMenu sub = menu.addSubMenu("Lista de Boards");
    Ion.with(getApplicationContext()).load("http://bienvenidoainternet.org/cgi/api/boards").asString()
            .setCallback(new FutureCallback<String>() {
                @Override/*  www .  j a v  a2  s  . c  o  m*/
                public void onCompleted(Exception e, String result) {
                    if (e != null) {
                        e.printStackTrace();
                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                    } else {
                        try {
                            JSONArray boards = new JSONObject(result).getJSONArray("boards");
                            for (int i = 0; i < boards.length(); i++) {
                                JSONObject board = boards.getJSONObject(i);
                                Board parsedBoard = new Board(board.getString("name"), board.getString("dir"),
                                        board.getInt("board_type"),
                                        board.getInt("allow_image_replies") == 1 ? true : false);
                                sub.add(parsedBoard.getBoardName());
                                boardList.add(parsedBoard);
                            }
                        } catch (JSONException e1) {
                            Toast.makeText(getApplicationContext(), e1.getMessage(), Toast.LENGTH_LONG).show();
                            e1.printStackTrace();
                        }
                    }
                }
            });
    refreshNavigator();
}

From source file:com.yacorso.nowaste.views.activities.DrawerActivity.java

private void loadNavItems() {
    int index = 0;
    Menu navigationMenu = navigationView.getMenu();
    navigationMenu.clear();/* ww  w . j  a v a  2s  .  c o  m*/
    navigationItems.clear();

    SubMenu fridgeSection = navigationMenu.addSubMenu(getText(R.string.menu_section_fridges));
    List<Fridge> fridges = currentUser.getFridges();
    for (Fridge fridge : fridges) {
        navigationItems.put(index, fridge);
        fridgeSection.add(0, index++, 0, fridge.getName()).setIcon(R.drawable.ic_fridge);
    }

    SubMenu customListSection = navigationMenu.addSubMenu(getText(R.string.menu_section_custom_lists));
    List<CustomList> customLists = currentUser.getCustomLists();

    for (CustomList customList : customLists) {
        navigationItems.put(index, customList);
        customListSection.add(1, index++, 0, customList.getName()).setIcon(R.drawable.ic_folder);
    }

    navigationMenu.add(2, index++, 0, R.string.menu_add_foodlist).setIcon(R.drawable.ic_add_circle_white);
    navigationMenu.add(3, index, 0, R.string.menu_title_settings).setIcon(R.drawable.ic_setting_dark);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getGroupId() < 2) {
                changeFragment(menuItem.getItemId(), true);
            } else if (menuItem.getGroupId() == 2) {
                launchDialog(ChooseTypeFoodListDialog.newInstance());
            } else if (menuItem.getGroupId() == 3) {
                changeFragment(menuItem.getItemId(), false);
            }

            return true;
        }
    });

    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });
}

From source file:org.bienvenidoainternet.app.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ThemeManager tm = new ThemeManager(this);
    this.setTheme(tm.getThemeForMainActivity());

    if (savedInstanceState != null) {
        currentThemeId = savedInstanceState.getInt("currentThemeId");
        boardList = savedInstanceState.getParcelableArrayList("boardList");
    }//from ww w. j  a  va 2s. c om
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    if (settings.getString("pref_password", "").isEmpty()) {
        SharedPreferences.Editor edit = settings.edit();
        edit.putString("pref_password", makePassword());
        edit.commit();
    }

    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Bievenido a internet");
    this.setSupportActionBar(toolbar);

    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (pager.getCurrentItem() == 0) {
                if (!mainFragment.getMode() && mainFragment.currentBoard != null) {
                    Intent in = new Intent(getApplicationContext(), ResponseActivity.class);
                    Bundle b = new Bundle();
                    BoardItem temp = new BoardItem();
                    temp.setParentBoard(mainFragment.currentBoard);
                    b.putParcelable("theReply", temp);
                    b.putBoolean("quoting", false);
                    b.putBoolean("newthread", true);
                    in.putExtras(b);
                    startActivity(in);
                }
            } else {
                if (childFragment.currentBoard != null) {
                    if (!childFragment.boardItems.isEmpty()) {
                        try {
                            Intent in = new Intent(getApplicationContext(), ResponseActivity.class);
                            Bundle b = new Bundle();
                            BoardItem reply = childFragment.boardItems.get(0);
                            if (!reply.isLocked) {
                                b.putParcelable("theReply", reply);
                                b.putBoolean("quoting", false);
                                b.putBoolean("newthread", false);
                                in.putExtras(b);
                                startActivity(in);
                            } else {
                                Toast.makeText(getApplicationContext(), "Error: Este hilo est cerrado",
                                        Toast.LENGTH_LONG).show();
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    });
    fab.setVisibility(View.GONE);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if (savedInstanceState != null) {
        mainFragment = (FragmentBoardItemList) getSupportFragmentManager().getFragment(savedInstanceState,
                "mainFragment");
        childFragment = (FragmentBoardItemList) getSupportFragmentManager().getFragment(savedInstanceState,
                "childFragment");
    } else {
        mainFragment = FragmentBoardItemList.newInstance(true, null, null);
        childFragment = FragmentBoardItemList.newInstance(false, null, null);
    }

    this.pager = (ViewPager) findViewById(R.id.pager);
    this.pagerAdapter = new CustomFragmentPagerAdapter(getSupportFragmentManager());
    pagerAdapter.addFragment(mainFragment);
    pagerAdapter.addFragment(childFragment);
    this.pager.setAdapter(pagerAdapter);

    pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                fab.setImageResource(R.drawable.ic_action_add);
                if (mainFragment.currentBoard != null) {
                    toolbar.setTitle("Catlogo");
                    toolbar.setSubtitle(mainFragment.currentBoard.getBoardName());
                }
                if (mainFragment.getMode()) {
                    toolbar.setTitle("Post recientes");
                    toolbar.setSubtitle("");
                }
                if (mainFragment.getMode()) {
                    fab.hide();
                } else {
                    fab.show();
                }
            } else if (position == 1) {
                fab.setImageResource(R.drawable.ic_edit);
                if (childFragment.currentBoard != null) {
                    toolbar.setTitle(childFragment.currentBoard.getBoardName());
                    if (!childFragment.boardItems.isEmpty()) {
                        toolbar.setSubtitle(childFragment.boardItems.get(0).getSubject());
                    }
                    fab.show();
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    if (boardList.isEmpty()) {
        getBoardList();
    } else {
        Menu menu = navigationView.getMenu();
        SubMenu sub = menu.addSubMenu("Lista de Boards");
        for (Board b : boardList) {
            sub.add(b.getBoardName());
        }
        refreshNavigator();
    }

    if (tm.isDarkTheme()) {
        navigationView.setBackgroundColor(0xFF888888);
    }
}