Add "Picasso" library; show header images in wikivoyage search list
This commit is contained in:
parent
de7d091724
commit
b651b913c0
5 changed files with 97 additions and 10 deletions
|
@ -414,6 +414,8 @@ dependencies {
|
|||
compile 'com.moparisthebest:junidecode:0.1.1'
|
||||
compile 'org.immutables:gson:2.5.0'
|
||||
compile 'com.vividsolutions:jts-core:1.14.0'
|
||||
|
||||
compile 'com.squareup.picasso:picasso:2.71828'
|
||||
// size restrictions
|
||||
// compile 'com.ibm.icu:icu4j:50.1'
|
||||
// compile 'net.sf.trove4j:trove4j:3.0.3'
|
||||
|
|
24
OsmAnd/res/drawable/wikivoyage_search_placeholder.xml
Normal file
24
OsmAnd/res/drawable/wikivoyage_search_placeholder.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/color_transparent"/>
|
||||
<size
|
||||
android:width="28dp"
|
||||
android:height="28dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/placeholder_icon"
|
||||
android:bottom="2dp"
|
||||
android:left="2dp"
|
||||
android:right="2dp"
|
||||
android:top="2dp">
|
||||
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@drawable/ic_action_placeholder_city"
|
||||
android:tint="@color/icon_color"/>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package net.osmand.plus.widgets.tools;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import com.squareup.picasso.Transformation;
|
||||
|
||||
public class CropCircleTransformation implements Transformation {
|
||||
|
||||
private static final String KEY = "CropCircleTransformation";
|
||||
|
||||
@Override
|
||||
public Bitmap transform(Bitmap source) {
|
||||
int size = Math.min(source.getWidth(), source.getHeight());
|
||||
|
||||
int width = (source.getWidth() - size) / 2;
|
||||
int height = (source.getHeight() - size) / 2;
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint();
|
||||
BitmapShader shader =
|
||||
new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
|
||||
if (width != 0 || height != 0) {
|
||||
// source isn't square, move viewport to center
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.setTranslate(-width, -height);
|
||||
shader.setLocalMatrix(matrix);
|
||||
}
|
||||
paint.setShader(shader);
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
float r = size / 2f;
|
||||
canvas.drawCircle(r, r, r, paint);
|
||||
|
||||
source.recycle();
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return KEY;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
package net.osmand.plus.wikivoyage.search;
|
||||
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -9,9 +12,12 @@ import android.view.ViewGroup;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.IconsCache;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.widgets.tools.CropCircleTransformation;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -23,7 +29,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
private static final int ITEM_TYPE = 1;
|
||||
|
||||
private OsmandApplication app;
|
||||
private IconsCache iconsCache;
|
||||
private LayerDrawable placeholder;
|
||||
|
||||
private List<Object> items = new ArrayList<>();
|
||||
|
||||
|
@ -35,7 +41,11 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
|
||||
SearchRecyclerViewAdapter(OsmandApplication app) {
|
||||
this.app = app;
|
||||
this.iconsCache = app.getIconsCache();
|
||||
placeholder = (LayerDrawable) ContextCompat.getDrawable(app, R.drawable.wikivoyage_search_placeholder);
|
||||
if (Build.VERSION.SDK_INT < 21 && placeholder != null) {
|
||||
placeholder.setDrawableByLayerId(R.id.placeholder_icon,
|
||||
app.getIconsCache().getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -60,9 +70,11 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
boolean lastItem = pos == getItemCount() - 1;
|
||||
|
||||
WikivoyageSearchResult item = (WikivoyageSearchResult) getItem(pos);
|
||||
holder.icon.setImageDrawable(
|
||||
iconsCache.getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color)
|
||||
);
|
||||
Picasso.get()
|
||||
.load(WikivoyageArticle.getThumbImageUrl(item.getImageTitle()))
|
||||
.transform(new CropCircleTransformation())
|
||||
.placeholder(placeholder)
|
||||
.into(holder.icon);
|
||||
holder.title.setText(item.getArticleTitles().get(0));
|
||||
holder.leftDescr.setText(item.getIsPartOf());
|
||||
holder.rightDescr.setText(item.getFirstLangsString());
|
||||
|
@ -102,7 +114,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
|
||||
final TextView title;
|
||||
|
||||
public HeaderVH(View itemView) {
|
||||
HeaderVH(View itemView) {
|
||||
super(itemView);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
}
|
||||
|
@ -117,7 +129,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
final View divider;
|
||||
final View shadow;
|
||||
|
||||
public ItemVH(View itemView) {
|
||||
ItemVH(View itemView) {
|
||||
super(itemView);
|
||||
icon = (ImageView) itemView.findViewById(R.id.icon);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
|
|
Loading…
Reference in a new issue