Search in sources :

Example 21 with RequestCreator

use of com.squareup.picasso.RequestCreator in project iNaturalistAndroid by inaturalist.

the class ProjectsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.observation_project_item, parent, false);
    final BetterJSONObject item = new BetterJSONObject(mItems.get(position));
    TextView projectName = (TextView) view.findViewById(R.id.project_name);
    final String projectTitle = item.getString(mIsUser ? "login" : "title");
    projectName.setText(projectTitle);
    ImageView projectPic = (ImageView) view.findViewById(R.id.project_pic);
    ImageView projectPicNone = (ImageView) view.findViewById(R.id.project_pic_none);
    ImageView userPic = (ImageView) view.findViewById(R.id.user_pic);
    ViewGroup projectPicContainer = (ViewGroup) view.findViewById(R.id.project_pic_container);
    if (mIsUser) {
        userPic.setVisibility(View.VISIBLE);
        projectPicContainer.setVisibility(View.INVISIBLE);
    }
    String iconUrl = item.has("icon") ? item.getString("icon") : item.getString("icon_url");
    if ((iconUrl == null) || (iconUrl.length() == 0)) {
        projectPic.setVisibility(View.GONE);
        projectPicNone.setVisibility(View.VISIBLE);
        RequestCreator req = Picasso.with(mContext).load(mDefaultIcon).fit().centerCrop().transform(new UserActivitiesAdapter.CircleTransform());
        if (mIsUser) {
            req = req.transform(new UserActivitiesAdapter.CircleTransform());
            req.into(userPic);
            userPic.setColorFilter(Color.parseColor("#5D5D5D"));
        } else {
            req.into(projectPicNone);
        }
    } else {
        projectPic.setVisibility(View.VISIBLE);
        projectPic.setImageResource(mDefaultIcon);
        UrlImageViewHelper.setUrlDrawable(projectPic, iconUrl);
        RequestCreator req = Picasso.with(mContext).load(iconUrl).fit().centerCrop().placeholder(mDefaultIcon);
        if (mIsUser) {
            req = req.transform(new UserActivitiesAdapter.CircleTransform());
            req.into(userPic);
            userPic.setColorFilter(null);
        } else {
            req.into(projectPic);
        }
        projectPicNone.setVisibility(View.GONE);
    }
    String description = item.getString("description");
    final String noHTMLDescription = Html.fromHtml(description != null ? description : "").toString();
    if ((noHTMLDescription.length() > 0) && (!mIsUser)) {
        ((ViewGroup) view.findViewById(R.id.project_pic_container)).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mHelper.alert(projectTitle, noHTMLDescription);
            }
        });
    } else {
        // No description - Hide the info button
        view.findViewById(R.id.project_pic_info).setVisibility(View.GONE);
    }
    view.setTag(item.getJSONObject().toString());
    return view;
}
Also used : ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RequestCreator(com.squareup.picasso.RequestCreator) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 22 with RequestCreator

use of com.squareup.picasso.RequestCreator in project iNaturalistAndroid by inaturalist.

the class TaxonSuggestionsActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    if (mTaxonSuggestions == null) {
        // Get taxon suggestions
        mTaxonSuggestionsReceiver = new TaxonSuggestionsReceiver();
        IntentFilter filter = new IntentFilter(INaturalistService.ACTION_GET_TAXON_SUGGESTIONS_RESULT);
        BaseFragmentActivity.safeRegisterReceiver(mTaxonSuggestionsReceiver, filter, this);
        Intent serviceIntent = new Intent(INaturalistService.ACTION_GET_TAXON_SUGGESTIONS, null, this, INaturalistService.class);
        serviceIntent.putExtra(INaturalistService.OBS_PHOTO_FILENAME, mObsPhotoFilename);
        serviceIntent.putExtra(INaturalistService.OBS_PHOTO_URL, mObsPhotoUrl);
        serviceIntent.putExtra(INaturalistService.LONGITUDE, mLongitude);
        serviceIntent.putExtra(INaturalistService.LATITUDE, mLatitude);
        serviceIntent.putExtra(INaturalistService.OBSERVED_ON, mObservedOn);
        startService(serviceIntent);
        mLoadingSuggestions.setVisibility(View.VISIBLE);
        mSuggestionsContainer.setVisibility(View.GONE);
    } else {
        loadSuggestions();
    }
    RequestCreator request;
    if (mObsPhotoFilename == null) {
        // Load online photo
        request = Picasso.with(this).load(mObsPhotoUrl);
    } else {
        // Load offline (local) photo
        request = Picasso.with(this).load(new File(mObsPhotoFilename));
    }
    request.fit().centerCrop().into(mObsPhoto, new Callback() {

        @Override
        public void onSuccess() {
        }

        @Override
        public void onError() {
        }
    });
    mObsPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(TaxonSuggestionsActivity.this, ObservationPhotosViewer.class);
            intent.putExtra(ObservationPhotosViewer.CURRENT_PHOTO_INDEX, 0);
            intent.putExtra(ObservationPhotosViewer.OBSERVATION, mObservationJson);
            intent.putExtra(ObservationPhotosViewer.OBSERVATION_ID, mObsId);
            intent.putExtra(ObservationPhotosViewer.OBSERVATION_ID_INTERNAL, mObsIdInternal);
            intent.putExtra(ObservationPhotosViewer.READ_ONLY, true);
            intent.putExtra(ObservationPhotosViewer.IS_NEW_OBSERVATION, mObsIdInternal == -1 ? false : true);
            startActivity(intent);
        }
    });
}
Also used : IntentFilter(android.content.IntentFilter) Callback(com.squareup.picasso.Callback) Intent(android.content.Intent) File(java.io.File) ImageView(android.widget.ImageView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) RequestCreator(com.squareup.picasso.RequestCreator)

Example 23 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 24 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)24 Picasso (com.squareup.picasso.Picasso)10 View (android.view.View)8 ImageView (android.widget.ImageView)8 TextView (android.widget.TextView)6 Bitmap (android.graphics.Bitmap)5 Drawable (android.graphics.drawable.Drawable)5 Target (com.squareup.picasso.Target)5 Callback (com.squareup.picasso.Callback)4 File (java.io.File)4 Intent (android.content.Intent)3 Uri (android.net.Uri)3 VafContext (com.tmall.wireless.vaf.framework.VafContext)3 IImageLoaderAdapter (com.tmall.wireless.vaf.virtualview.Helper.ImageLoader.IImageLoaderAdapter)3 NonNull (android.support.annotation.NonNull)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ViewGroup (android.view.ViewGroup)2 Listener (com.tmall.wireless.vaf.virtualview.Helper.ImageLoader.Listener)2 ImageBase (com.tmall.wireless.vaf.virtualview.view.image.ImageBase)2 ArrayList (java.util.ArrayList)2