fix center crop issue / improve layout
This commit is contained in:
parent
29adf8d6e6
commit
7162409878
5 changed files with 119 additions and 10 deletions
|
@ -23,7 +23,6 @@ import android.widget.TextView;
|
|||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
|
@ -40,6 +39,7 @@ import de.luhmer.owncloudnewsreader.database.model.RssItem;
|
|||
import de.luhmer.owncloudnewsreader.helper.ColorHelper;
|
||||
import de.luhmer.owncloudnewsreader.helper.FavIconHandler;
|
||||
import de.luhmer.owncloudnewsreader.helper.ImageHandler;
|
||||
import de.luhmer.owncloudnewsreader.helper.SquareRoundedBitmapDisplayer;
|
||||
import de.luhmer.owncloudnewsreader.services.PodcastDownloadService;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
|
@ -131,12 +131,11 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL
|
|||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
|
||||
|
||||
displayImageOptionsThumbnail = new DisplayImageOptions.Builder()
|
||||
.displayer(new RoundedBitmapDisplayer(30))
|
||||
//.showImageOnLoading(placeHolder)
|
||||
//.showImageForEmptyUri(placeHolder)
|
||||
//.showImageOnFail(placeHolder)
|
||||
.displayer(new SquareRoundedBitmapDisplayer(30))
|
||||
.showImageOnLoading(R.drawable.feed_icon)
|
||||
.showImageForEmptyUri(R.drawable.feed_icon)
|
||||
.showImageOnFail(R.drawable.feed_icon)
|
||||
.cacheOnDisk(true)
|
||||
.cacheInMemory(true)
|
||||
.build();
|
||||
|
@ -294,8 +293,8 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL
|
|||
// Show Podcast Icon if no thumbnail is available but it is a podcast (otherwise the podcast button will go missing)
|
||||
if (DatabaseConnectionOrm.ALLOWED_PODCASTS_TYPES.contains(rssItem.getEnclosureMime())) {
|
||||
imgViewThumbnail.setVisibility(View.VISIBLE);
|
||||
imgViewThumbnail.setColorFilter(Color.parseColor("#d8d8d8"));
|
||||
imgViewThumbnail.setImageDrawable(ContextCompat.getDrawable(itemView.getContext(), R.drawable.default_feed_icon_dark));
|
||||
//imgViewThumbnail.setColorFilter(Color.parseColor("#d8d8d8"));
|
||||
imgViewThumbnail.setImageDrawable(ContextCompat.getDrawable(itemView.getContext(), R.drawable.feed_icon));
|
||||
} else {
|
||||
imgViewThumbnail.setVisibility(GONE);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package de.luhmer.owncloudnewsreader.helper;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
|
||||
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
|
||||
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
|
||||
|
||||
public class SquareRoundedBitmapDisplayer implements BitmapDisplayer {
|
||||
|
||||
protected final int cornerRadius;
|
||||
protected final int margin;
|
||||
|
||||
public SquareRoundedBitmapDisplayer(int cornerRadiusPixels) {
|
||||
this(cornerRadiusPixels, 0);
|
||||
}
|
||||
|
||||
public SquareRoundedBitmapDisplayer(int cornerRadiusPixels, int marginPixels) {
|
||||
this.cornerRadius = cornerRadiusPixels;
|
||||
this.margin = marginPixels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
|
||||
if (!(imageAware instanceof ImageViewAware)) {
|
||||
throw new IllegalArgumentException("ImageAware should wrap ImageView. ImageViewAware is expected.");
|
||||
}
|
||||
|
||||
//imageAware.setImageDrawable(new RoundedDrawable(bitmap, cornerRadius, margin));
|
||||
imageAware.setImageDrawable(new RoundedDrawable(bitmap, cornerRadius));
|
||||
}
|
||||
|
||||
public static class RoundedDrawable extends Drawable {
|
||||
|
||||
private Bitmap bitmap;
|
||||
private Paint maskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private Paint borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private int side;
|
||||
private float cornerRadius;
|
||||
private RectF dst;
|
||||
|
||||
public RoundedDrawable(Bitmap wrappedBitmap, int cornerRadius) {
|
||||
bitmap = wrappedBitmap;
|
||||
borderPaint.setStyle(Paint.Style.STROKE);
|
||||
borderPaint.setStrokeWidth(16);
|
||||
borderPaint.setColor(0xcc220088);
|
||||
side = Math.min(bitmap.getWidth(), bitmap.getHeight());
|
||||
this.cornerRadius = cornerRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
Matrix matrix = new Matrix();
|
||||
RectF src = new RectF(0, 0, side, side);
|
||||
src.offset((bitmap.getWidth() - side) / 2f, (bitmap.getHeight() - side) / 2f);
|
||||
dst = new RectF(bounds);
|
||||
dst.inset(borderPaint.getStrokeWidth() / 4f, borderPaint.getStrokeWidth() / 4f); // Adjust the factor here to fit into the bounds
|
||||
matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
|
||||
|
||||
Shader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
||||
shader.setLocalMatrix(matrix);
|
||||
maskPaint.setShader(shader);
|
||||
matrix.mapRect(src);
|
||||
//radius = src.width() / 2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
//Rect b = getBounds();
|
||||
//canvas.drawCircle(b.exactCenterX(), b.exactCenterY(), radius, maskPaint);
|
||||
//canvas.drawCircle(b.exactCenterX(), b.exactCenterY(), radius + borderPaint.getStrokeWidth() / 2, borderPaint);
|
||||
canvas.drawRoundRect(dst, cornerRadius, cornerRadius, maskPaint);
|
||||
}
|
||||
|
||||
@Override public void setAlpha(int alpha) {}
|
||||
@Override public void setColorFilter(ColorFilter cf) {}
|
||||
@Override public int getOpacity() {return PixelFormat.TRANSLUCENT;}
|
||||
|
||||
}
|
||||
}
|
9
News-Android-App/src/main/res/drawable/feed_icon.xml
Normal file
9
News-Android-App/src/main/res/drawable/feed_icon.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector android:height="24dp" android:viewportHeight="96"
|
||||
android:viewportWidth="96" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@color/material_grey_600"
|
||||
android:pathData="M4,13.2l0,9.5 7.8,0.6c19.3,1.3 39.6,13.8 50.7,31.1 5.4,8.5 9.6,20.6 10.2,29.8l0.6,7.8 9.3,-0c10.9,-0 10.2,1.2 8,-13.5 -2.7,-17.8 -10.1,-33.5 -22,-46.2 -15.3,-16.5 -34,-25.4 -57.8,-27.9l-6.8,-0.6 0,9.4z" android:strokeColor="#00000000"/>
|
||||
<path android:fillColor="@color/material_grey_600"
|
||||
android:pathData="M4,41.9l0,8.8 6.6,1.2c9.3,1.7 17.1,5.9 23.1,12.5 6,6.5 8.8,12.2 10.4,21l1.2,6.6 8.9,-0 8.9,-0 -0.6,-4.8c-2.1,-16.3 -6.9,-26.7 -17.1,-36.8 -10,-10.1 -21.4,-15.3 -36.6,-16.7l-4.8,-0.5 0,8.7z" android:strokeColor="#00000000"/>
|
||||
<path android:fillColor="@color/material_grey_600"
|
||||
android:pathData="M10.2,69c-6.6,4.1 -7.8,13.5 -2.4,19 8.2,8.2 22,1.6 20.9,-9.9 -1,-8.9 -10.9,-13.9 -18.5,-9.1z" android:strokeColor="#00000000"/>
|
||||
</vector>
|
10
News-Android-App/src/main/res/drawable/rounded_rectangle.xml
Normal file
10
News-Android-App/src/main/res/drawable/rounded_rectangle.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<solid android:color="#00ffffff" />
|
||||
<padding android:left="6dp"
|
||||
android:top="6dp"
|
||||
android:right="6dp"
|
||||
android:bottom="6dp" />
|
||||
<corners android:radius="12dp" />
|
||||
<stroke android:width="6dp" android:color="#ffffffff" />
|
||||
</shape>
|
|
@ -49,14 +49,14 @@
|
|||
android:layout_marginEnd="16dp"
|
||||
android:contentDescription="@string/img_view_thumbnail"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@drawable/default_feed_icon_dark" />
|
||||
tools:src="@drawable/feed_icon" />
|
||||
|
||||
<include
|
||||
android:id="@+id/podcast_wrapper"
|
||||
layout="@layout/subscription_detail_list_item_podcast_wrapper"
|
||||
android:layout_height="88dp"
|
||||
android:layout_width="88dp"
|
||||
android:layout_below="@id/star_imageview"/>
|
||||
android:layout_below="@id/summary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/body"
|
||||
|
|
Loading…
Reference in a new issue