fix icon size

This commit is contained in:
tobiasKaminsky 2017-04-07 08:46:29 +02:00
parent 82b02788d0
commit 3c75cf9b9b
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
3 changed files with 47 additions and 18 deletions

View file

@ -193,15 +193,16 @@ public class ExternalLinksProvider {
.into(imageView);
}
private void downloadSVGIcon(Context context, String iconUrl, SimpleTarget imageView, int placeholder) {
private void downloadSVGIcon(Context context, String iconUrl, SimpleTarget imageView, int placeholder,
int width, int height) {
GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(context)
.using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class)
.from(Uri.class)
.as(SVG.class)
.transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
.sourceEncoder(new StreamEncoder())
.cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder()))
.decoder(new SvgDecoder())
.cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder(height, width)))
.decoder(new SvgDecoder(height, width))
.placeholder(placeholder)
.error(placeholder)
.animate(android.R.anim.fade_in);
@ -215,9 +216,10 @@ public class ExternalLinksProvider {
}
public void downloadIcon(Context context, String iconUrl, SimpleTarget imageView, int placeholder){
public void downloadIcon(Context context, String iconUrl, SimpleTarget imageView, int placeholder,
int width, int height){
if (iconUrl.endsWith(".svg")){
downloadSVGIcon(context, iconUrl, imageView, placeholder);
downloadSVGIcon(context, iconUrl, imageView, placeholder, width, height);
} else {
downloadPNGIcon(context, iconUrl, imageView, placeholder);
}

View file

@ -29,7 +29,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PictureDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@ -771,6 +770,9 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
ArrayList<ExternalLink> quotas = externalLinksProvider.getExternalLink(ExternalLinkType.QUOTA);
float density = getResources().getDisplayMetrics().density;
final int size = Math.round(24 * density);
if (quotas.size() > 0) {
final ExternalLink firstQuota = quotas.get(0);
mQuotaTextLink.setText(firstQuota.name);
@ -788,22 +790,26 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
});
SimpleTarget target = new SimpleTarget<PictureDrawable>() {
SimpleTarget target = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(PictureDrawable resource, GlideAnimation glideAnimation) {
mQuotaTextLink.setCompoundDrawablesWithIntrinsicBounds(resource.getCurrent(), null,
null, null);
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
Drawable test = resource.getCurrent();
test.setBounds(0, 0, size, size);
mQuotaTextLink.setCompoundDrawablesWithIntrinsicBounds(test, null, null, null);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
mQuotaTextLink.setCompoundDrawablesWithIntrinsicBounds(errorDrawable, null, null, null);
Drawable test = errorDrawable.getCurrent();
test.setBounds(0, 0, size, size);
mQuotaTextLink.setCompoundDrawablesWithIntrinsicBounds(test, null, null, null);
}
};
externalLinksProvider.downloadIcon(this, firstQuota.iconUrl, target, R.drawable.ic_link_grey);
externalLinksProvider.downloadIcon(this, firstQuota.iconUrl, target, R.drawable.ic_link_grey, size, size);
} else {
mQuotaTextLink.setVisibility(View.INVISIBLE);
@ -902,10 +908,14 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
public void updateExternalLinksInDrawer() {
if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
mNavigationView.getMenu().removeGroup(R.id.drawer_menu_external_links);
float density = getResources().getDisplayMetrics().density;
final int size = Math.round(24 * density);
for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
SimpleTarget target = new SimpleTarget<PictureDrawable>() {
SimpleTarget target = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(PictureDrawable resource, GlideAnimation glideAnimation) {
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
MENU_ORDER_EXTERNAL_LINKS, link.name)
.setIcon(resource.getCurrent());
@ -914,14 +924,13 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
MENU_ORDER_EXTERNAL_LINKS, link.name)
.setIcon(errorDrawable);
.setIcon(errorDrawable.getCurrent());
}
};
externalLinksProvider.downloadIcon(this, link.iconUrl, target, R.drawable.ic_link_grey);
externalLinksProvider.downloadIcon(this, link.iconUrl, target, R.drawable.ic_link_grey, size, size);
}
}
}

View file

@ -14,6 +14,7 @@ package com.owncloud.android.utils.svg;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.resource.SimpleResource;
import com.caverock.androidsvg.PreserveAspectRatio;
import com.caverock.androidsvg.SVG;
import com.caverock.androidsvg.SVGParseException;
@ -24,9 +25,26 @@ import java.io.InputStream;
* Decodes an SVG internal representation from an {@link InputStream}.
*/
public class SvgDecoder implements ResourceDecoder<InputStream, SVG> {
public Resource<SVG> decode(InputStream source, int width, int height) throws IOException {
private int height = -1;
private int width = -1;
public SvgDecoder(){
}
public SvgDecoder(int height, int width) {
this.height = height;
this.width = width;
}
public Resource<SVG> decode(InputStream source, int w, int h) throws IOException {
try {
SVG svg = SVG.getFromInputStream(source);
if (width > 0) svg.setDocumentWidth(width);
if (height > 0) svg.setDocumentHeight(height);
svg.setDocumentPreserveAspectRatio(PreserveAspectRatio.LETTERBOX);
return new SimpleResource<SVG>(svg);
} catch (SVGParseException ex) {
throw new IOException("Cannot load SVG from stream", ex);