Search in sources :

Example 26 with RequestCreator

use of com.squareup.picasso.RequestCreator 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)

Example 27 with RequestCreator

use of com.squareup.picasso.RequestCreator in project scissors by lyft.

the class PicassoBitmapLoader method load.

@Override
public void load(@Nullable Object model, @NonNull ImageView imageView) {
    final RequestCreator requestCreator;
    if (model instanceof Uri || model == null) {
        requestCreator = picasso.load((Uri) model);
    } else if (model instanceof String) {
        requestCreator = picasso.load((String) model);
    } else if (model instanceof File) {
        requestCreator = picasso.load((File) model);
    } else if (model instanceof Integer) {
        requestCreator = picasso.load((Integer) model);
    } else {
        throw new IllegalArgumentException("Unsupported model " + model);
    }
    requestCreator.skipMemoryCache().transform(transformation).into(imageView);
}
Also used : Uri(android.net.Uri) File(java.io.File) RequestCreator(com.squareup.picasso.RequestCreator)

Aggregations

RequestCreator (com.squareup.picasso.RequestCreator)27 Picasso (com.squareup.picasso.Picasso)10 View (android.view.View)8 ImageView (android.widget.ImageView)8 TextView (android.widget.TextView)8 Bitmap (android.graphics.Bitmap)5 Drawable (android.graphics.drawable.Drawable)5 VafContext (com.tmall.wireless.vaf.framework.VafContext)5 IImageLoaderAdapter (com.tmall.wireless.vaf.virtualview.Helper.ImageLoader.IImageLoaderAdapter)5 Listener (com.tmall.wireless.vaf.virtualview.Helper.ImageLoader.Listener)5 ImageBase (com.tmall.wireless.vaf.virtualview.view.image.ImageBase)5 ArrayList (java.util.ArrayList)5 RecyclerView (android.support.v7.widget.RecyclerView)4 Target (com.squareup.picasso.Target)4 File (java.io.File)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 TargetApi (android.annotation.TargetApi)3 Intent (android.content.Intent)3 Uri (android.net.Uri)3