Search in sources :

Example 1 with CropCircleTransformation

use of net.osmand.plus.widgets.tools.CropCircleTransformation in project Osmand by osmandapp.

the class AMapPointMenuController method getPointDrawable.

@Nullable
private Drawable getPointDrawable() {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return null;
    }
    String imageUriStr = point.getParams().get(AMapPoint.POINT_IMAGE_URI_PARAM);
    if (TextUtils.isEmpty(imageUriStr)) {
        return null;
    }
    Uri fileUri = Uri.parse(imageUriStr);
    try {
        InputStream ims = mapActivity.getContentResolver().openInputStream(fileUri);
        if (ims != null) {
            Bitmap bitmap = BitmapFactory.decodeStream(ims);
            if (bitmap != null) {
                bitmap = new CropCircleTransformation().transform(bitmap);
                return new BitmapDrawable(mapActivity.getResources(), bitmap);
            }
            ims.close();
        }
    } catch (Exception e) {
    // ignore
    }
    return null;
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) CropCircleTransformation(net.osmand.plus.widgets.tools.CropCircleTransformation) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Uri(android.net.Uri) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(androidx.annotation.Nullable)

Example 2 with CropCircleTransformation

use of net.osmand.plus.widgets.tools.CropCircleTransformation in project Osmand by osmandapp.

the class SavedArticlesRvAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
    if (viewHolder instanceof HeaderVH) {
        final HeaderVH holder = (HeaderVH) viewHolder;
        holder.title.setText((String) getItem(position));
        holder.description.setText(String.valueOf(items.size() - 1));
    } else if (viewHolder instanceof ItemVH) {
        final ItemVH holder = (ItemVH) viewHolder;
        TravelArticle article = (TravelArticle) getItem(position);
        final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
        Boolean loaded = picasso.isURLLoaded(url);
        boolean lastItem = position == getItemCount() - 1;
        RequestCreator rc = Picasso.get().load(url);
        WikivoyageUtils.setupNetworkPolicy(settings, rc);
        rc.transform(new CropCircleTransformation()).into(holder.icon, new Callback() {

            @Override
            public void onSuccess() {
                holder.icon.setVisibility(View.VISIBLE);
                picasso.setResultLoaded(url, true);
            }

            @Override
            public void onError(Exception e) {
                holder.icon.setVisibility(View.GONE);
                picasso.setResultLoaded(url, false);
            }
        });
        holder.icon.setVisibility(loaded == null || loaded.booleanValue() ? View.VISIBLE : View.GONE);
        holder.title.setText(article.getTitle());
        holder.content.setText(WikiArticleHelper.getPartialContent(article.getContent()));
        holder.partOf.setText(article.getGeoDescription());
        holder.leftButton.setText(app.getString(R.string.shared_string_read));
        holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null);
        holder.rightButton.setText(app.getString(R.string.shared_string_remove));
        holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, deleteIcon, null);
        holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
        holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
    } else if (viewHolder instanceof TravelGpxVH) {
        final TravelGpx article = (TravelGpx) getItem(position);
        final TravelGpxVH holder = (TravelGpxVH) viewHolder;
        holder.title.setText(article.getTitle());
        holder.userIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_user_account_16));
        holder.user.setText(article.user);
        String activityTypeKey = article.activityType;
        if (!Algorithms.isEmpty(activityTypeKey)) {
            RouteActivityType activityType = RouteActivityType.getOrCreateTypeFromName(activityTypeKey);
            int activityTypeIcon = getActivityTypeIcon(activityType);
            holder.activityTypeIcon.setImageDrawable(getActiveIcon(activityTypeIcon));
            holder.activityType.setText(getActivityTypeTitle(activityType));
            holder.activityTypeLabel.setVisibility(View.VISIBLE);
        }
        holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
        holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
        holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app));
        holder.leftButton.setText(app.getString(R.string.shared_string_view));
        View.OnClickListener readClickListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.openArticle(article);
                }
            }
        };
        holder.leftButton.setOnClickListener(readClickListener);
        holder.itemView.setOnClickListener(readClickListener);
        holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null);
        updateSaveButton(holder, article);
    }
}
Also used : TravelGpx(net.osmand.plus.wikivoyage.data.TravelGpx) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RequestCreator(com.squareup.picasso.RequestCreator) TravelGpxVH(net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH) Callback(com.squareup.picasso.Callback) RouteActivityType(net.osmand.osm.RouteActivityType) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) CropCircleTransformation(net.osmand.plus.widgets.tools.CropCircleTransformation)

Example 3 with CropCircleTransformation

use of net.osmand.plus.widgets.tools.CropCircleTransformation in project Osmand by osmandapp.

the class ArticleTravelCard method bindViewHolder.

@Override
public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
    if (viewHolder instanceof ArticleTravelVH) {
        final ArticleTravelVH holder = (ArticleTravelVH) viewHolder;
        final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
        Boolean loaded = picasso.isURLLoaded(url);
        RequestCreator rc = Picasso.get().load(url);
        WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
        rc.transform(new CropCircleTransformation()).into(holder.icon, new Callback() {

            @Override
            public void onSuccess() {
                holder.icon.setVisibility(View.VISIBLE);
                picasso.setResultLoaded(url, true);
            }

            @Override
            public void onError(Exception e) {
                holder.icon.setVisibility(View.GONE);
                picasso.setResultLoaded(url, false);
            }
        });
        holder.icon.setVisibility(loaded == null || loaded.booleanValue() ? View.VISIBLE : View.GONE);
        holder.title.setText(article.getTitle());
        holder.content.setText(WikiArticleHelper.getPartialContent(article.getContent()));
        holder.partOf.setText(article.getGeoDescription());
        holder.leftButton.setText(app.getString(R.string.shared_string_read));
        View.OnClickListener readClickListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (fragmentManager != null) {
                    WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, article.generateIdentifier(), article.getLang());
                }
            }
        };
        holder.leftButton.setOnClickListener(readClickListener);
        holder.itemView.setOnClickListener(readClickListener);
        holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null);
        updateSaveButton(holder);
        holder.divider.setVisibility(isLastItem ? View.GONE : View.VISIBLE);
        holder.shadow.setVisibility(isLastItem ? View.VISIBLE : View.GONE);
    }
}
Also used : Callback(com.squareup.picasso.Callback) CropCircleTransformation(net.osmand.plus.widgets.tools.CropCircleTransformation) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RequestCreator(com.squareup.picasso.RequestCreator)

Example 4 with CropCircleTransformation

use of net.osmand.plus.widgets.tools.CropCircleTransformation in project Osmand by osmandapp.

the class SearchRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int pos) {
    if (viewHolder instanceof HeaderVH) {
        ((HeaderVH) viewHolder).title.setText((String) getItem(pos));
    } else {
        ItemVH holder = (ItemVH) viewHolder;
        boolean lastItem = pos == getItemCount() - 1;
        Object item = getItem(pos);
        if (item instanceof WikivoyageSearchResult) {
            WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
            RequestCreator rc = Picasso.get().load(TravelArticle.getImageUrl(searchRes.getImageTitle(), true));
            WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
            rc.transform(new CropCircleTransformation()).placeholder(placeholder).into(holder.icon);
            holder.title.setText(searchRes.getArticleTitle());
            holder.leftDescr.setText(searchRes.getIsPartOf());
            holder.rightDescr.setText(searchRes.getFirstLangsString());
        } else {
            WikivoyageSearchHistoryItem historyItem = (WikivoyageSearchHistoryItem) item;
            holder.icon.setImageDrawable(historyPlaceholder);
            holder.title.setText(historyItem.getArticleTitle());
            holder.leftDescr.setText(historyItem.getIsPartOf());
            holder.rightDescr.setText(Algorithms.capitalizeFirstLetter(historyItem.getLang()));
        }
        holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
        holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
    }
}
Also used : WikivoyageSearchHistoryItem(net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem) CropCircleTransformation(net.osmand.plus.widgets.tools.CropCircleTransformation) WikivoyageSearchResult(net.osmand.plus.wikivoyage.data.WikivoyageSearchResult) RequestCreator(com.squareup.picasso.RequestCreator)

Aggregations

CropCircleTransformation (net.osmand.plus.widgets.tools.CropCircleTransformation)4 RequestCreator (com.squareup.picasso.RequestCreator)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 Callback (com.squareup.picasso.Callback)2 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Uri (android.net.Uri)1 Nullable (androidx.annotation.Nullable)1 InputStream (java.io.InputStream)1 RouteActivityType (net.osmand.osm.RouteActivityType)1 MapActivity (net.osmand.plus.activities.MapActivity)1 TravelArticle (net.osmand.plus.wikivoyage.data.TravelArticle)1 TravelGpx (net.osmand.plus.wikivoyage.data.TravelGpx)1 WikivoyageSearchHistoryItem (net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem)1 WikivoyageSearchResult (net.osmand.plus.wikivoyage.data.WikivoyageSearchResult)1 TravelGpxVH (net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH)1