Example usage for android.view SubMenu getItem

List of usage examples for android.view SubMenu getItem

Introduction

In this page you can find the example usage for android.view SubMenu getItem.

Prototype

public MenuItem getItem(int index);

Source Link

Document

Gets the menu item at the given index.

Usage

From source file:org.totschnig.myexpenses.fragment.TransactionList.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (mAccount == null || getActivity() == null) {
        //mAccount seen in report 3331195c529454ca6b25a4c5d403beda
        //getActivity seen in report 68a501c984bdfcc95b40050af4f815bf
        return;// ww  w  .ja  v a 2s  .  com
    }
    MenuItem searchMenu = menu.findItem(R.id.SEARCH_COMMAND);
    if (searchMenu != null) {
        String title;
        Drawable searchMenuIcon = searchMenu.getIcon();
        if (!mFilter.isEmpty()) {
            if (searchMenuIcon != null) {
                searchMenuIcon.setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY);
            } else {
                AcraHelper.report(new Exception("Search menu icon not found"));
            }
            searchMenu.setChecked(true);
            title = mAccount.label + " ( " + mFilter.prettyPrint() + " )";
        } else {
            if (searchMenuIcon != null) {
                searchMenuIcon.setColorFilter(null);
            } else {
                AcraHelper.report(new Exception("Search menu icon not found"));
            }
            searchMenu.setChecked(false);
            title = mAccount.label;
        }
        ((MyExpenses) getActivity()).setTitle(title);
        SubMenu filterMenu = searchMenu.getSubMenu();
        for (int i = 0; i < filterMenu.size(); i++) {
            MenuItem filterItem = filterMenu.getItem(i);
            boolean enabled = true;
            switch (filterItem.getItemId()) {
            case R.id.FILTER_CATEGORY_COMMAND:
                enabled = mappedCategories;
                break;
            case R.id.FILTER_STATUS_COMMAND:
                enabled = !mAccount.type.equals(AccountType.CASH);
                break;
            case R.id.FILTER_PAYEE_COMMAND:
                enabled = mappedPayees;
                break;
            case R.id.FILTER_METHOD_COMMAND:
                enabled = mappedMethods;
                break;
            case R.id.FILTER_TRANSFER_COMMAND:
                enabled = hasTransfers;
                break;
            }
            Criteria c = mFilter.get(filterItem.getItemId());
            Utils.menuItemSetEnabledAndVisible(filterItem, enabled || c != null);
            if (c != null) {
                filterItem.setChecked(true);
                filterItem.setTitle(c.prettyPrint());
            }
        }
    } else {
        AcraHelper.report(new Exception("Search menu not found"));
    }
}

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.ja va2s .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;
        }
    });

}

From source file:com.tweetlanes.android.view.TweetFeedFragment.java

@Override
public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) {

    if (inflater != null && mContentHandle != null
            && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) {

        if (getBaseLaneActivity() instanceof HomeActivity) {
            inflater.inflate(R.menu.home_tweet_feed_action_bar, menu);
        } else {// w w w  . j av  a2s  .  c o m
            inflater.inflate(R.menu.tweet_feed_action_bar, menu);
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            if (menuItem.getItemId() == R.id.action_feed_filter) {
                SubMenu subMenu = menuItem.getSubMenu();
                if (subMenu != null) {
                    SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType();
                    int subMenuSize = subMenu.size();
                    for (int j = 0; j < subMenuSize; j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        switch (subMenuItem.getItemId()) {
                        case R.id.action_replies_visibility:

                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies()
                                            ? R.string.action_hide_replies
                                            : R.string.action_show_replies));
                            break;

                        case R.id.action_retweets_visibility:
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets()
                                            ? socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_hide_retweets
                                                    : R.string.action_hide_retweets_adn
                                            : socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_show_retweets
                                                    : R.string.action_show_retweets_adn));
                            break;

                        default:
                            break;
                        }

                    }
                }
            }
        }

        return true;
    }

    return false;
}

From source file:com.dycody.android.idealnote.ListFragment.java

private void initSortingSubmenu() {
    final String[] arrayDb = getResources().getStringArray(R.array.sortable_columns);
    final String[] arrayDialog = getResources().getStringArray(R.array.sortable_columns_human_readable);
    int selected = Arrays.asList(arrayDb).indexOf(prefs.getString(Constants.PREF_SORTING_COLUMN, arrayDb[0]));

    SubMenu sortMenu = this.menu.findItem(R.id.menu_sort).getSubMenu();
    for (int i = 0; i < arrayDialog.length; i++) {
        if (sortMenu.findItem(i) == null) {
            sortMenu.add(Constants.MENU_SORT_GROUP_ID, i, i, arrayDialog[i]);
        }//from w  ww.  j  a v  a2s .co  m
        if (i == selected)
            sortMenu.getItem(i).setChecked(true);
    }
    sortMenu.setGroupCheckable(Constants.MENU_SORT_GROUP_ID, true, true);
}

From source file:com.tweetlanes.android.core.view.TweetFeedFragment.java

@Override
public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) {

    if (inflater != null && mContentHandle != null
            && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) {

        if (getBaseLaneActivity() instanceof HomeActivity) {
            inflater.inflate(R.menu.home_tweet_feed_action_bar, menu);
        } else {//  w  ww .j av a  2s.com
            inflater.inflate(R.menu.tweet_feed_action_bar, menu);
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            if (menuItem.getItemId() == R.id.action_feed_filter) {
                SubMenu subMenu = menuItem.getSubMenu();
                if (subMenu != null) {
                    SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType();
                    int subMenuSize = subMenu.size();
                    for (int j = 0; j < subMenuSize; j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        int i1 = subMenuItem.getItemId();
                        if (i1 == R.id.action_replies_visibility) {
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies()
                                            ? R.string.action_hide_replies
                                            : R.string.action_show_replies));

                        } else if (i1 == R.id.action_retweets_visibility) {
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets()
                                            ? socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_hide_retweets
                                                    : R.string.action_hide_retweets_adn
                                            : socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_show_retweets
                                                    : R.string.action_show_retweets_adn));

                        } else {
                        }

                    }
                }
            }
        }

        return true;
    }

    return false;
}