mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 10:18:59 +03:00
fix icon size
This commit is contained in:
parent
82b02788d0
commit
3c75cf9b9b
3 changed files with 47 additions and 18 deletions
|
@ -193,15 +193,16 @@ public class ExternalLinksProvider {
|
||||||
.into(imageView);
|
.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)
|
GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(context)
|
||||||
.using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class)
|
.using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class)
|
||||||
.from(Uri.class)
|
.from(Uri.class)
|
||||||
.as(SVG.class)
|
.as(SVG.class)
|
||||||
.transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
|
.transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
|
||||||
.sourceEncoder(new StreamEncoder())
|
.sourceEncoder(new StreamEncoder())
|
||||||
.cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder()))
|
.cacheDecoder(new FileToStreamDecoder<>(new SvgDecoder(height, width)))
|
||||||
.decoder(new SvgDecoder())
|
.decoder(new SvgDecoder(height, width))
|
||||||
.placeholder(placeholder)
|
.placeholder(placeholder)
|
||||||
.error(placeholder)
|
.error(placeholder)
|
||||||
.animate(android.R.anim.fade_in);
|
.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")){
|
if (iconUrl.endsWith(".svg")){
|
||||||
downloadSVGIcon(context, iconUrl, imageView, placeholder);
|
downloadSVGIcon(context, iconUrl, imageView, placeholder, width, height);
|
||||||
} else {
|
} else {
|
||||||
downloadPNGIcon(context, iconUrl, imageView, placeholder);
|
downloadPNGIcon(context, iconUrl, imageView, placeholder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.PictureDrawable;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
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)) {
|
if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
|
||||||
ArrayList<ExternalLink> quotas = externalLinksProvider.getExternalLink(ExternalLinkType.QUOTA);
|
ArrayList<ExternalLink> quotas = externalLinksProvider.getExternalLink(ExternalLinkType.QUOTA);
|
||||||
|
|
||||||
|
float density = getResources().getDisplayMetrics().density;
|
||||||
|
final int size = Math.round(24 * density);
|
||||||
|
|
||||||
if (quotas.size() > 0) {
|
if (quotas.size() > 0) {
|
||||||
final ExternalLink firstQuota = quotas.get(0);
|
final ExternalLink firstQuota = quotas.get(0);
|
||||||
mQuotaTextLink.setText(firstQuota.name);
|
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
|
@Override
|
||||||
public void onResourceReady(PictureDrawable resource, GlideAnimation glideAnimation) {
|
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
|
||||||
mQuotaTextLink.setCompoundDrawablesWithIntrinsicBounds(resource.getCurrent(), null,
|
Drawable test = resource.getCurrent();
|
||||||
null, null);
|
test.setBounds(0, 0, size, size);
|
||||||
|
mQuotaTextLink.setCompoundDrawablesWithIntrinsicBounds(test, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||||
super.onLoadFailed(e, 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 {
|
} else {
|
||||||
mQuotaTextLink.setVisibility(View.INVISIBLE);
|
mQuotaTextLink.setVisibility(View.INVISIBLE);
|
||||||
|
@ -902,10 +908,14 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
|
||||||
public void updateExternalLinksInDrawer() {
|
public void updateExternalLinksInDrawer() {
|
||||||
if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
|
if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
|
||||||
mNavigationView.getMenu().removeGroup(R.id.drawer_menu_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)) {
|
for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
|
||||||
SimpleTarget target = new SimpleTarget<PictureDrawable>() {
|
SimpleTarget target = new SimpleTarget<Drawable>() {
|
||||||
@Override
|
@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,
|
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
|
||||||
MENU_ORDER_EXTERNAL_LINKS, link.name)
|
MENU_ORDER_EXTERNAL_LINKS, link.name)
|
||||||
.setIcon(resource.getCurrent());
|
.setIcon(resource.getCurrent());
|
||||||
|
@ -914,14 +924,13 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
||||||
super.onLoadFailed(e, errorDrawable);
|
super.onLoadFailed(e, errorDrawable);
|
||||||
|
|
||||||
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
|
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
|
||||||
MENU_ORDER_EXTERNAL_LINKS, link.name)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ package com.owncloud.android.utils.svg;
|
||||||
import com.bumptech.glide.load.ResourceDecoder;
|
import com.bumptech.glide.load.ResourceDecoder;
|
||||||
import com.bumptech.glide.load.engine.Resource;
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
import com.bumptech.glide.load.resource.SimpleResource;
|
import com.bumptech.glide.load.resource.SimpleResource;
|
||||||
|
import com.caverock.androidsvg.PreserveAspectRatio;
|
||||||
import com.caverock.androidsvg.SVG;
|
import com.caverock.androidsvg.SVG;
|
||||||
import com.caverock.androidsvg.SVGParseException;
|
import com.caverock.androidsvg.SVGParseException;
|
||||||
|
|
||||||
|
@ -24,9 +25,26 @@ import java.io.InputStream;
|
||||||
* Decodes an SVG internal representation from an {@link InputStream}.
|
* Decodes an SVG internal representation from an {@link InputStream}.
|
||||||
*/
|
*/
|
||||||
public class SvgDecoder implements ResourceDecoder<InputStream, SVG> {
|
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 {
|
try {
|
||||||
SVG svg = SVG.getFromInputStream(source);
|
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);
|
return new SimpleResource<SVG>(svg);
|
||||||
} catch (SVGParseException ex) {
|
} catch (SVGParseException ex) {
|
||||||
throw new IOException("Cannot load SVG from stream", ex);
|
throw new IOException("Cannot load SVG from stream", ex);
|
||||||
|
|
Loading…
Reference in a new issue