Search in sources :

Example 56 with MenuItem

use of android.view.MenuItem in project cardslib by gabrielemariotti.

the class GoogleNowNativeWeatherCard method initCardHeader.

@Override
protected CardHeader initCardHeader() {
    //Add Header
    CardHeader header = new CardHeader(getContext(), R.layout.carddemo_googlenowweather_native_inner_header);
    //Add a popup menu. This method set OverFlow button to visible
    header.setPopupMenu(R.menu.popup_item, new CardHeader.OnClickCardHeaderPopupMenuListener() {

        @Override
        public void onMenuItemClick(BaseCard card, MenuItem item) {
            switch(item.getItemId()) {
                case R.id.action_add:
                    //Example: add an item
                    WeatherObject w1 = new WeatherObject(GoogleNowNativeWeatherCard.this);
                    w1.city = "Madrid";
                    w1.temperature = 24;
                    w1.weatherIcon = R.drawable.ic_action_sun;
                    w1.setObjectId(w1.city);
                    mLinearListAdapter.add(w1);
                    break;
                case R.id.action_remove:
                    //Example: remove an item
                    mLinearListAdapter.remove(mLinearListAdapter.getItem(0));
                    break;
            }
        }
    });
    //should use R.string.
    header.setTitle("Weather");
    return header;
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem)

Example 57 with MenuItem

use of android.view.MenuItem in project cardslib by gabrielemariotti.

the class GoogleNowWeatherCard method initCardHeader.

@Override
protected CardHeader initCardHeader() {
    //Add Header
    CardHeader header = new CardHeader(getContext(), R.layout.carddemo_googlenowweather_inner_header);
    //Add a popup menu. This method set OverFlow button to visible
    header.setPopupMenu(R.menu.popup_item, new CardHeader.OnClickCardHeaderPopupMenuListener() {

        @Override
        public void onMenuItemClick(BaseCard card, MenuItem item) {
            switch(item.getItemId()) {
                case R.id.action_add:
                    //Example: add an item
                    WeatherObject w1 = new WeatherObject(GoogleNowWeatherCard.this);
                    w1.city = "Madrid";
                    w1.temperature = 24;
                    w1.weatherIcon = R.drawable.ic_action_sun;
                    w1.setObjectId(w1.city);
                    mLinearListAdapter.add(w1);
                    break;
                case R.id.action_remove:
                    //Example: remove an item
                    mLinearListAdapter.remove(mLinearListAdapter.getItem(0));
                    break;
            }
        }
    });
    //should use R.string.
    header.setTitle("Weather");
    return header;
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem)

Example 58 with MenuItem

use of android.view.MenuItem in project cardslib by gabrielemariotti.

the class NativeHeaderFragment method init_standard_header_with_overflow_button.

/**
     * This method builds a standard header with overflow button
     */
private void init_standard_header_with_overflow_button() {
    //Create a Card
    Card card = new Card(getActivity());
    //Create a CardHeader
    CardHeader header = new CardHeader(getActivity());
    //Set the header title
    header.setTitle(getString(R.string.demo_header_basetitle));
    //Add a popup menu. This method set OverFlow button to visible
    header.setPopupMenu(R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {

        @Override
        public void onMenuItemClick(BaseCard card, MenuItem item) {
            Toast.makeText(getActivity(), "Click on " + item.getTitle(), Toast.LENGTH_SHORT).show();
        }
    });
    card.addCardHeader(header);
    //Set card in the CardViewNative
    CardViewNative cardViewNative = (CardViewNative) getActivity().findViewById(R.id.carddemo_header_overflow);
    cardViewNative.setCard(card);
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CustomExpandCard(it.gmariotti.cardslib.demo.cards.CustomExpandCard) CustomHeaderInnerCard(it.gmariotti.cardslib.demo.cards.CustomHeaderInnerCard) Card(it.gmariotti.cardslib.library.internal.Card) CardViewNative(it.gmariotti.cardslib.library.view.CardViewNative)

Example 59 with MenuItem

use of android.view.MenuItem in project cardslib by gabrielemariotti.

the class NativeHeaderFragment method init_standard_header_with_overflow_button_dynamic_menu.

/**
     * This method builds a standard header with overflow button with a dynamic menu
     */
private void init_standard_header_with_overflow_button_dynamic_menu() {
    //Create a Card
    Card card = new Card(getActivity());
    //Create a CardHeader
    CardHeader header = new CardHeader(getActivity());
    //Set the header title
    header.setTitle(getString(R.string.demo_header_basetitle));
    //Add a popup menu. This method set OverFlow button to visible
    header.setPopupMenu(R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {

        @Override
        public void onMenuItemClick(BaseCard card, MenuItem item) {
            Toast.makeText(getActivity(), "Click on " + item.getTitle(), Toast.LENGTH_SHORT).show();
        }
    });
    //Add a PopupMenuPrepareListener to add dynamically a menu entry
    //it is optional.
    header.setPopupMenuPrepareListener(new CardHeader.OnPrepareCardHeaderPopupMenuListener() {

        @Override
        public boolean onPreparePopupMenu(BaseCard card, PopupMenu popupMenu) {
            popupMenu.getMenu().add("Dynamic item");
            return true;
        }
    });
    card.addCardHeader(header);
    //Set card in the CardViewNative
    CardViewNative cardViewNative = (CardViewNative) getActivity().findViewById(R.id.carddemo_header_overflow_dynamic);
    cardViewNative.setCard(card);
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CustomExpandCard(it.gmariotti.cardslib.demo.cards.CustomExpandCard) CustomHeaderInnerCard(it.gmariotti.cardslib.demo.cards.CustomHeaderInnerCard) Card(it.gmariotti.cardslib.library.internal.Card) PopupMenu(android.widget.PopupMenu) CardViewNative(it.gmariotti.cardslib.library.view.CardViewNative)

Example 60 with MenuItem

use of android.view.MenuItem in project cardslib by gabrielemariotti.

the class NativeFabFragment method initCard.

/**
     * This method builds a simple list of cards
     */
private ArrayList<Card> initCard() {
    //Init an array of Cards
    ArrayList<Card> cards = new ArrayList<Card>();
    for (int i = 0; i < 200; i++) {
        Card card = new Card(this.getActivity());
        card.setTitle("Application example " + i);
        //Create a CardHeader
        CardHeader header = new CardHeader(getActivity());
        //Set the header title
        header.setTitle(getString(R.string.demo_header_basetitle));
        if (i < 10) {
            //Add a popup menu. This method set OverFlow button to visible
            header.setPopupMenu(R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {

                @Override
                public void onMenuItemClick(BaseCard card, MenuItem item) {
                    Toast.makeText(getActivity(), "Click on " + item.getTitle(), Toast.LENGTH_SHORT).show();
                }
            });
            card.addCardHeader(header);
        } else {
            //Set visible the expand/collapse button
            header.setButtonExpandVisible(true);
            card.addCardHeader(header);
            //This provides a simple (and useless) expand area
            CardExpand expand = new CardExpand(getActivity());
            //Set inner title in Expand Area
            expand.setTitle(getString(R.string.demo_expand_basetitle));
            card.addCardExpand(expand);
            if (i == 12 || i == 17 || i == 19)
                card.setExpanded(true);
        }
        //Add ClickListener
        card.setOnClickListener(new Card.OnCardClickListener() {

            @Override
            public void onClick(Card card, View view) {
                Toast.makeText(getActivity(), "Click Listener card=" + card.getTitle(), Toast.LENGTH_SHORT).show();
            }
        });
        cards.add(card);
    }
    return cards;
}
Also used : CardExpand(it.gmariotti.cardslib.library.internal.CardExpand) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) ArrayList(java.util.ArrayList) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) MenuItem(android.view.MenuItem) CardListView(it.gmariotti.cardslib.library.view.CardListView) View(android.view.View) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) Card(it.gmariotti.cardslib.library.internal.Card)

Aggregations

MenuItem (android.view.MenuItem)761 View (android.view.View)140 Intent (android.content.Intent)86 TextView (android.widget.TextView)78 PopupMenu (android.widget.PopupMenu)62 ImageView (android.widget.ImageView)58 Menu (android.view.Menu)52 SearchView (android.support.v7.widget.SearchView)46 SmallTest (android.test.suitebuilder.annotation.SmallTest)42 RecyclerView (android.support.v7.widget.RecyclerView)36 MenuInflater (android.view.MenuInflater)35 AdapterView (android.widget.AdapterView)33 ListView (android.widget.ListView)32 SubMenu (android.view.SubMenu)30 ComponentName (android.content.ComponentName)25 PackageManager (android.content.pm.PackageManager)25 Parcelable (android.os.Parcelable)24 Toolbar (android.support.v7.widget.Toolbar)24 Bundle (android.os.Bundle)19 PopupMenu (android.support.v7.widget.PopupMenu)19