Example usage for android.view Menu size

List of usage examples for android.view Menu size

Introduction

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

Prototype

public int size();

Source Link

Document

Get the number of items in the menu.

Usage

From source file:com.github.shareme.gwsmaterialuikit.library.material.app.ToolbarManager.java

/**
 * This function should be called in onPrepareOptionsMenu(Menu) of Activity that use
 * Toolbar as ActionBar, or after inflating menu.
 *///www.  j a va  2 s.c o m
public void onPrepareMenu() {
    if (mGroupChanged || mMenuDataChanged) {
        mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);

        Menu menu = mToolbar.getMenu();
        for (int i = 0, count = menu.size(); i < count; i++) {
            MenuItem item = menu.getItem(i);
            item.setVisible(item.getGroupId() == mCurrentGroup || item.getGroupId() == 0);
        }

        mMenuDataChanged = false;
    }
}

From source file:com.example.volunteerhandbook.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (!noDrawYet && mDrawerLayout != null)
        mDrawerLayout.isDrawerOpen(mDrawerList);
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setVisible(false);
    }/*from  w  w  w  .  j  a  v  a 2  s  .  c o  m*/
    //menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
    mActionMenu = menu;
    return super.onPrepareOptionsMenu(menu);
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Try to tint all {@link Menu}s {@link MenuItem}s with given color
 *//*from www .  j  av  a2  s.  c  o  m*/
@SuppressWarnings("ConstantConditions")
public void tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        try {
            tintDrawable(item.getIcon(), iconColor);
            if (item.hasSubMenu() && recurse) {
                tintMenuItems(item.getSubMenu(), recurse, iconColor);
            }
        } catch (Exception ignored) {
            // This should not happen at all, but may in bad menu.xml configuration
        }
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.MessagingActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        switch (item.getItemId()) {
        case R.id.select_all:
        case R.id.deselect_all:
            item.setVisible(mEditing);/*from   ww w . ja v  a2s  .c o  m*/
            break;
        case R.id.delete_messages:
            item.setEnabled(((CursorAdapter) getListAdapter()).getCursor().getCount() > 0);
            //$FALL-THROUGH$
        default:
            item.setVisible(!mEditing);
            break;
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

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

public boolean onPrepareOptionsMenu(Menu menu) {
    // We start out with every option enabled. Based on the current view, we disable actions
    // that are possible.
    LogUtils.d(LOG_TAG, "ActionBarView.onPrepareOptionsMenu().");

    if (mController.shouldHideMenuItems()) {
        // Shortcut: hide all menu items if the drawer is shown
        final int size = menu.size();

        for (int i = 0; i < size; i++) {
            final MenuItem item = menu.getItem(i);
            item.setVisible(false);//from www  .  ja v  a 2  s  .  c  om
        }
        return false;
    }
    validateVolatileMenuOptionVisibility();

    switch (getMode()) {
    case ViewMode.CONVERSATION:
    case ViewMode.SEARCH_RESULTS_CONVERSATION:
        // We update the ActionBar options when we are entering conversation view because
        // waiting for the AbstractConversationViewFragment to do it causes duplicate icons
        // to show up during the time between the conversation is selected and the fragment
        // is added.
        setConversationModeOptions(menu);
        break;
    case ViewMode.CONVERSATION_LIST:
        // Show search if the account supports it
        Utils.setMenuItemVisibility(menu, R.id.search, mAccount.supportsSearch());
        break;
    case ViewMode.SEARCH_RESULTS_LIST:
        // Hide compose and search
        Utils.setMenuItemVisibility(menu, R.id.compose, false);
        Utils.setMenuItemVisibility(menu, R.id.search, false);
        break;
    }

    return false;
}

From source file:org.dvbviewer.controller.ui.fragments.ChannelPager.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    inflater.inflate(R.menu.channel_list, menu);
    for (int i = 0; i < menu.size(); i++) {
        if (menu.getItem(i).getItemId() == R.id.menuChannelList) {
            menu.getItem(i).setVisible(showFavs);
        } else if (menu.getItem(i).getItemId() == R.id.menuFavourties) {
            menu.getItem(i).setVisible(!showFavs);
        }//from w w  w  .j  a v a  2 s  . co m
    }
    menu.findItem(R.id.menuChannelList).setVisible(showFavs);
    menu.findItem(R.id.menuFavourties).setVisible(!showFavs);
    if (getActivity() instanceof ChannelListMultiActivity) {
        menu.findItem(R.id.menu_refresh_now_playing).setVisible(false);
        menu.findItem(R.id.menuRefreshChannels).setVisible(false);
    }
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.ApptentiveBaseFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(getMenuResourceId(), menu);
    // Make menu icon color same as toolbar up arrow. Both use ?colorControlNormal
    // By default colorControlNormal has same value as textColorPrimary defined in toolbar theme overlay
    int colorControlNormal = Util.getThemeColor(ApptentiveInternal.getInstance().getApptentiveToolbarTheme(),
            R.attr.colorControlNormal);/*from   w  w  w . j a  v a  2 s  . c om*/
    for (int i = 0; i < menu.size(); i++) {
        Drawable drawable = menu.getItem(i).getIcon();
        if (drawable != null) {
            drawable.mutate();
            drawable.setColorFilter(colorControlNormal, PorterDuff.Mode.SRC_ATOP);
        }
    }
    attachFragmentMenuListeners(menu);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java

private void createNavDrawerItems(NavigationModel.NavigationItemEnum[] items) {
    if (mNavigationView != null) {
        Menu menu = mNavigationView.getMenu();
        for (int i = 0; i < items.length; i++) {
            MenuItem item = menu.findItem(items[i].getId());
            if (item != null) {
                item.setVisible(true);/*  ww w  . j a  v a  2 s .c om*/
                item.setIcon(items[i].getIcon());
                item.setTitle(items[i].getTitleResource());
            } else {
                LogUtils.LOGE(TAG,
                        "Menu Item for navigation item with title " + (items[i].getTitleResource() != 0
                                ? mActivity.getResources().getString(items[i].getTitleResource())
                                : "") + "not found");
            }
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem mi = menu.getItem(i);
            applyFontToSubMenu(mi);
            applyFontToMenuItem(mi);
        }

        mNavigationView.setNavigationItemSelectedListener(this);
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.FriendsThreadActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        switch (item.getItemId()) {
        case R.id.members:
            item.setVisible(!SystemUtils.isFlagEnabled(mFlags, MessagingPlugin.FLAG_DYNAMIC_CHAT));
            break;
        case R.id.delete_conversation:
            item.setVisible(!SystemUtils.isFlagEnabled(mFlags, MessagingPlugin.FLAG_NOT_REMOVABLE));
            break;
        case R.id.info:
            item.setVisible(SystemUtils.isFlagEnabled(mFlags, MessagingPlugin.FLAG_DYNAMIC_CHAT));
            break;
        }/*from   www.  j ava2  s .  co m*/
    }
    return true;
}

From source file:com.techno.jay.codingcontests.Home.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    FirebaseApp.initializeApp(this);

    FontChangeCrawler fontChanger = new FontChangeCrawler(getAssets(), "fonts/ProductSans-Regular.ttf");
    fontChanger.replaceFonts((ViewGroup) this.findViewById(android.R.id.content));
    //==2) for fragment hoy to====
    //== fontChanger.replaceFonts((ViewGroup) this.getView());
    //===3) for adepterview and handlerview na use mate====
    //==convertView = inflater.inflate(R.layout.listitem, null);
    //==fontChanger.replaceFonts((ViewGroup)convertView);

    bp = new BillingProcessor(Home.this, Const.LICENSE_KEY, Home.this);
    /*bp.consumeAsync(inventory.getPurchase(SKU_GAS),
        mConsumeFinishedListener);*/
    bp.consumePurchase(Const.Product_Plan_Unlimitedversion);

    Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*  w  ww.  j  a  va2 s. c  o  m*/

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.drawable.appicon);

    /*     if (Build.VERSION.SDK_INT >= 21) {
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.setStatusBarColor(Color.parseColor("#1976D2"));
    window.setNavigationBarColor(Color.parseColor("#1976D2"));
         }*/

    sharepref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);

    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(
                android.Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[] { android.Manifest.permission.READ_PHONE_STATE },
                    PERMISSIONS_REQUEST_READ_PHONE_STATE);
        } else {
            getDeviceImei();
        }
    } else {
        getDeviceImei();
    }

    databaseReferenceUser = FirebaseDatabase.getInstance().getReference("Users");
    //databaseReferenceUser.keepSynced(true);

    token = FirebaseInstanceId.getInstance().getToken();

    SimpleDateFormat format_diffrent = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
    Date now = new Date();
    date = format_diffrent.format(now);

    // creating connection detector class instance
    ConnectionDetector cd = new ConnectionDetector(getApplicationContext());
    // get Internet status
    isInternetPresent = cd.isConnectingToInternet();
    if (isInternetPresent) {
        // Internet Connection is Present
        // make HTTP requests
        //refreshedToken = FirebaseInstanceId.getInstance().getToken();
        databaseReferenceUser.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                // Get user value

                if (dataSnapshot.hasChild(str_IMEI)) {
                    String IMEI_no = dataSnapshot.child("IMEI").getValue(String.class);
                    String date_got = dataSnapshot.child("date").getValue(String.class);
                    Log.d("date got", date_got);
                    String status_got = dataSnapshot.child("status").getValue(String.class);

                    Toast.makeText(Home.this, "  Already registered. !   ", Toast.LENGTH_LONG).show();
                    SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");

                    try {
                        Date date1 = myFormat.parse(date_got);
                        Date date2 = myFormat.parse(date);
                        long diff = date2.getTime() - date1.getTime();
                        System.out.println("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));

                        long days_count = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);

                        if (days_count > 10 && status_got.equalsIgnoreCase("inactive")) {
                            promptForUpgrade();
                        }

                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                //  Log.w("TAG", "getUser:onCancelled", databaseError.toException());
                // new Signup_async().execute();
            }
        });

    } else {

        Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), " Sorry! No Internet!!!",
                Snackbar.LENGTH_LONG);

        // Changing message text color
        snackbar.setActionTextColor(Color.BLUE);

        // Changing action button text color
        View sbView = snackbar.getView();
        TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setTextColor(Color.YELLOW);
        snackbar.show();

        Toast.makeText(Home.this, "  No Internet Connection!!!.  ", Toast.LENGTH_LONG).show();

    }

    Set<String> set = sharepref.getStringSet("arraylist", null);
    List<String> sposers = new ArrayList<String>(set);

    String[] apossor_arry = new String[sposers.size()];
    apossor_arry = sposers.toArray(apossor_arry);

    FragmentTransaction tx;
    tx = getSupportFragmentManager().beginTransaction();
    tx.replace(R.id.frame, new MainHomeFragmentFirebase());
    tx.commit();

    searchView = (MaterialSearchView) findViewById(R.id.search_view);
    searchView.setVoiceSearch(false);
    searchView.setHint("Enter Coding website/technology");
    searchView.setCursorDrawable(R.drawable.custome_cursor);
    searchView.setSuggestions(apossor_arry);
    searchView.setEllipsize(true);

    searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Snackbar.make(findViewById(android.R.id.content), "Query: " + query, Snackbar.LENGTH_LONG).show();
            Intent result = new Intent(Home.this, ResultContestLink.class);
            result.putExtra("query", query);

            startActivity(result);
            overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            //Do some magic
            return false;
        }
    });

    searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
        @Override
        public void onSearchViewShown() {
            //Do some magic
        }

        @Override
        public void onSearchViewClosed() {
            //Do some magic
        }
    });

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle Toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

        @Override
        public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank

            super.onDrawerOpened(drawerView);
        }
    };
    //Setting the actionbarToggle to drawer layout
    drawer.setDrawerListener(Toggle);
    //calling sync state is necessay or else your hamburger icon wont show up
    Toggle.syncState();

    databaseReferenceEventData = FirebaseDatabase.getInstance().getReference("Contest").child("objects");
    databaseReferenceEventData.keepSynced(true);

    //Initializing NavigationView
    navigationView = (NavigationView) findViewById(R.id.nav_view);

    Menu m = navigationView.getMenu();
    for (int i = 0; i < m.size(); i++) {
        MenuItem mi = m.getItem(i);

        //for aapplying a font to subMenu ...
        SubMenu subMenu = mi.getSubMenu();
        if (subMenu != null && subMenu.size() > 0) {
            for (int j = 0; j < subMenu.size(); j++) {
                MenuItem subMenuItem = subMenu.getItem(j);
                applyFontToMenuItem(subMenuItem);
            }
        }

        //the method we have create in activity
        applyFontToMenuItem(mi);
    }

    View header = navigationView.getHeaderView(0);
    tv_total_sponsers = (TextView) header.findViewById(R.id.tv_total_sponsers);
    tv_total_contests = (TextView) header.findViewById(R.id.tv_total_contests);

    tv_total_sponsers.setText("Total Contests websites : " + sharepref.getString("totalsposor", "NA"));

    // navigationView.setNavigationItemSelectedListener(this);

    //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
    assert navigationView != null;
    navigationView.setCheckedItem(R.id.nav_home);
    navigationView.getMenu().getItem(0).setChecked(true);
    navigationView.setItemIconTintList(null);

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            navigationView.getMenu().getItem(0).setChecked(false);

            //Checking if the item is in checked state or not, if not make it in checked state
            if (activeMenuItem != null)
                activeMenuItem.setChecked(false);
            activeMenuItem = menuItem;
            menuItem.setChecked(true);
            //else menuItem.setChecked(true);

            //Closing drawer on item click
            drawer.closeDrawers();
            Fragment fragment = null;
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();

            //Check to see which item was being clicked and perform appropriate action
            switch (menuItem.getItemId()) {

            //Replacing the main content with ContentFragment Which is our Inbox View;
            case R.id.nav_home:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment = new MainHomeFragmentFirebase();
                break;

            case R.id.nav_longcompetition:

                fragment = new LongtermCompetition();
                break;
            case R.id.nav_exit:
                System.exit(0);
                getIntent().setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                break;
            case R.id.nav_running:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment = new LiveContests();
                break;

            case R.id.nav_past:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment = new CompletedContest();
                break;

            case R.id.nav_share:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();

                Intent intentshare = new Intent(Intent.ACTION_SEND);
                intentshare.setType("text/plain");
                intentshare.putExtra(Intent.EXTRA_TEXT,
                        "Best Competitive Programming news/reminder app for Coders.World wide coding competitions and hiring challenges.Solve the challenges and get chance to win awesome prizes and also hired by world famous MNCs(i.e AMAZON , IBM , intel , google , SAP many more...).\n\n\n"
                                + "https://play.google.com/store/apps/details?id=com.techno.jay.codingcontests&hl=en"
                                + "\n\n-developed by Technocrats Appware");
                startActivity(Intent.createChooser(intentshare, "Share"));

                break;
            case R.id.nav_feedback:
                final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
                try {
                    startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
                } catch (Exception e) {
                    // Log.d("TAG","Message ="+e);
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                            "https://play.google.com/store/apps/details?id=com.techno.jay.codingcontests&hl=en")));
                }
                break;

            case R.id.nav_hiring:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                Intent result = new Intent(Home.this, ResultContestLink.class);
                result.putExtra("query", "hiring");

                startActivity(result);
                overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
                break;

            case R.id.nav_setting:
                Intent seting = new Intent(Home.this, Setting_app.class);
                startActivity(seting);
                overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
                break;

            case R.id.nav_aboutus:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment = new Aboutus();
                break;

            /*case R.id.nav_aboutus:
                // Toast.makeText(getApplicationContext(),"Shop",Toast.LENGTH_SHORT).show();
                fragment= new Aboutus_fragment();
                break;
                    
            case R.id.spam:
                Toast.makeText(getApplicationContext(),"Spam Selected",Toast.LENGTH_SHORT).show();
                return true;*/
            default:
                Toast.makeText(getApplicationContext(), "Coming Soon...", Toast.LENGTH_SHORT).show();

                break;

            }

            if (fragment != null) {

                fragmentTransaction.replace(R.id.frame, fragment);
                //getSupportFragmentManager().beginTransaction().replace(R.id.frame, fragment).addToBackStack(null).commit();
                fragmentTransaction.addToBackStack(null).commit();

                getSupportActionBar().setTitle("Coding Contests");

            } else {
                menuItem.setChecked(false);
            }

            return true;
        }
    });

}