Search in sources :

Example 1 with OnActionClickListener

use of com.dexafree.materialList.card.OnActionClickListener in project MaterialList by dexafree.

the class MainActivity method getRandomCard.

private Card getRandomCard(final int position) {
    String title = "Card number " + (position + 1);
    String description = "Lorem ipsum dolor sit amet";
    switch(position % 7) {
        case 0:
            {
                return new Card.Builder(this).setTag("SMALL_IMAGE_CARD").setDismissible().withProvider(new CardProvider()).setLayout(R.layout.material_small_image_card).setTitle(title).setDescription(description).setDrawable(R.drawable.sample_android).setDrawableConfiguration(new CardProvider.OnImageConfigListener() {

                    @Override
                    public void onImageConfigure(@NonNull final RequestCreator requestCreator) {
                        requestCreator.rotate(position * 90.0f).resize(150, 150).centerCrop();
                    }
                }).endConfig().build();
            }
        case 1:
            {
                return new Card.Builder(this).setTag("BIG_IMAGE_CARD").withProvider(new CardProvider()).setLayout(R.layout.material_big_image_card_layout).setTitle(title).setSubtitle(description).setSubtitleGravity(Gravity.END).setDrawable("https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png").setDrawableConfiguration(new CardProvider.OnImageConfigListener() {

                    @Override
                    public void onImageConfigure(@NonNull final RequestCreator requestCreator) {
                        requestCreator.rotate(position * 45.0f).resize(200, 200).centerCrop();
                    }
                }).endConfig().build();
            }
        case 2:
            {
                final CardProvider provider = new Card.Builder(this).setTag("BASIC_IMAGE_BUTTON_CARD").setDismissible().withProvider(new CardProvider<>()).setLayout(R.layout.material_basic_image_buttons_card_layout).setTitle(title).setTitleGravity(Gravity.END).setDescription(description).setDescriptionGravity(Gravity.END).setDrawable(R.drawable.dog).setDrawableConfiguration(new CardProvider.OnImageConfigListener() {

                    @Override
                    public void onImageConfigure(@NonNull RequestCreator requestCreator) {
                        requestCreator.fit();
                    }
                }).addAction(R.id.left_text_button, new TextViewAction(this).setText("left").setTextResourceColor(R.color.black_button).setListener(new OnActionClickListener() {

                    @Override
                    public void onActionClicked(View view, Card card) {
                        Toast.makeText(mContext, "You have pressed the left button", Toast.LENGTH_SHORT).show();
                        card.getProvider().setTitle("CHANGED ON RUNTIME");
                    }
                })).addAction(R.id.right_text_button, new TextViewAction(this).setText("right").setTextResourceColor(R.color.orange_button).setListener(new OnActionClickListener() {

                    @Override
                    public void onActionClicked(View view, Card card) {
                        Toast.makeText(mContext, "You have pressed the right button on card " + card.getProvider().getTitle(), Toast.LENGTH_SHORT).show();
                        card.dismiss();
                    }
                }));
                if (position % 2 == 0) {
                    provider.setDividerVisible(true);
                }
                return provider.endConfig().build();
            }
        case 3:
            {
                final CardProvider provider = new Card.Builder(this).setTag("BASIC_BUTTONS_CARD").setDismissible().withProvider(new CardProvider()).setLayout(R.layout.material_basic_buttons_card).setTitle(title).setDescription(description).addAction(R.id.left_text_button, new TextViewAction(this).setText("left").setTextResourceColor(R.color.black_button).setListener(new OnActionClickListener() {

                    @Override
                    public void onActionClicked(View view, Card card) {
                        Toast.makeText(mContext, "You have pressed the left button", Toast.LENGTH_SHORT).show();
                    }
                })).addAction(R.id.right_text_button, new TextViewAction(this).setText("right").setTextResourceColor(R.color.accent_material_dark).setListener(new OnActionClickListener() {

                    @Override
                    public void onActionClicked(View view, Card card) {
                        Toast.makeText(mContext, "You have pressed the right button", Toast.LENGTH_SHORT).show();
                    }
                }));
                if (position % 2 == 0) {
                    provider.setDividerVisible(true);
                }
                return provider.endConfig().build();
            }
        case 4:
            {
                final CardProvider provider = new Card.Builder(this).setTag("WELCOME_CARD").setDismissible().withProvider(new CardProvider()).setLayout(R.layout.material_welcome_card_layout).setTitle("Welcome Card").setTitleColor(Color.WHITE).setDescription("I am the description").setDescriptionColor(Color.WHITE).setSubtitle("My subtitle!").setSubtitleColor(Color.WHITE).setBackgroundColor(Color.BLUE).addAction(R.id.ok_button, new WelcomeButtonAction(this).setText("Okay!").setTextColor(Color.WHITE).setListener(new OnActionClickListener() {

                    @Override
                    public void onActionClicked(View view, Card card) {
                        Toast.makeText(mContext, "Welcome!", Toast.LENGTH_SHORT).show();
                    }
                }));
                if (position % 2 == 0) {
                    provider.setBackgroundResourceColor(android.R.color.background_dark);
                }
                return provider.endConfig().build();
            }
        case 5:
            {
                ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
                adapter.add("Hello");
                adapter.add("World");
                adapter.add("!");
                return new Card.Builder(this).setTag("LIST_CARD").setDismissible().withProvider(new ListCardProvider()).setLayout(R.layout.material_list_card_layout).setTitle("List Card").setDescription("Take a list").setAdapter(adapter).endConfig().build();
            }
        default:
            {
                final CardProvider provider = new Card.Builder(this).setTag("BIG_IMAGE_BUTTONS_CARD").setDismissible().withProvider(new CardProvider()).setLayout(R.layout.material_image_with_buttons_card).setTitle(title).setDescription(description).setDrawable(R.drawable.photo).addAction(R.id.left_text_button, new TextViewAction(this).setText("add card").setTextResourceColor(R.color.black_button).setListener(new OnActionClickListener() {

                    @Override
                    public void onActionClicked(View view, Card card) {
                        Log.d("ADDING", "CARD");
                        mListView.getAdapter().add(generateNewCard());
                        Toast.makeText(mContext, "Added new card", Toast.LENGTH_SHORT).show();
                    }
                })).addAction(R.id.right_text_button, new TextViewAction(this).setText("right button").setTextResourceColor(R.color.accent_material_dark).setListener(new OnActionClickListener() {

                    @Override
                    public void onActionClicked(View view, Card card) {
                        Toast.makeText(mContext, "You have pressed the right button", Toast.LENGTH_SHORT).show();
                    }
                }));
                if (position % 2 == 0) {
                    provider.setDividerVisible(true);
                }
                return provider.endConfig().build();
            }
    }
}
Also used : WelcomeButtonAction(com.dexafree.materialList.card.action.WelcomeButtonAction) TextViewAction(com.dexafree.materialList.card.action.TextViewAction) MaterialListView(com.dexafree.materialList.view.MaterialListView) ImageView(android.widget.ImageView) View(android.view.View) OnActionClickListener(com.dexafree.materialList.card.OnActionClickListener) Card(com.dexafree.materialList.card.Card) RequestCreator(com.squareup.picasso.RequestCreator) CardProvider(com.dexafree.materialList.card.CardProvider) ListCardProvider(com.dexafree.materialList.card.provider.ListCardProvider) NonNull(android.support.annotation.NonNull) ArrayAdapter(android.widget.ArrayAdapter) ListCardProvider(com.dexafree.materialList.card.provider.ListCardProvider)

Aggregations

NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 ImageView (android.widget.ImageView)1 Card (com.dexafree.materialList.card.Card)1 CardProvider (com.dexafree.materialList.card.CardProvider)1 OnActionClickListener (com.dexafree.materialList.card.OnActionClickListener)1 TextViewAction (com.dexafree.materialList.card.action.TextViewAction)1 WelcomeButtonAction (com.dexafree.materialList.card.action.WelcomeButtonAction)1 ListCardProvider (com.dexafree.materialList.card.provider.ListCardProvider)1 MaterialListView (com.dexafree.materialList.view.MaterialListView)1 RequestCreator (com.squareup.picasso.RequestCreator)1