Added SVG favicon support

pull/199/head
M66B 3 years ago
parent 98e69c1338
commit 39e77350c2

@ -32,3 +32,4 @@ FairEmail uses:
* [POI-HMEF](https://poi.apache.org/components/hmef/index.html). Copyright © 2001-2020 The Apache Software Foundation. [Apache Software License v2](https://poi.apache.org/devel/guidelines.html#The+Licensing). * [POI-HMEF](https://poi.apache.org/components/hmef/index.html). Copyright © 2001-2020 The Apache Software Foundation. [Apache Software License v2](https://poi.apache.org/devel/guidelines.html#The+Licensing).
* [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt). * [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt).
* [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt). * [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt).
* [AndroidSVG](https://github.com/BigBadaboom/androidsvg). Copyright 2013 Paul LeBeau, Cave Rock Software Ltd. [Apache License 2.0](https://github.com/BigBadaboom/androidsvg/blob/master/LICENSE).

@ -302,6 +302,7 @@ dependencies {
def apache_poi = "3.17" // Do not update def apache_poi = "3.17" // Do not update
def reactivestreams_version = "1.0.3" def reactivestreams_version = "1.0.3"
def rxjava2_version = "2.2.21" def rxjava2_version = "2.2.21"
def svg_version = "1.4"
// https://developer.android.com/jetpack/androidx/releases/startup // https://developer.android.com/jetpack/androidx/releases/startup
implementation "androidx.startup:startup-runtime:$startup_version" implementation "androidx.startup:startup-runtime:$startup_version"
@ -483,4 +484,7 @@ dependencies {
// https://mvnrepository.com/artifact/io.reactivex.rxjava2/rxjava // https://mvnrepository.com/artifact/io.reactivex.rxjava2/rxjava
implementation "org.reactivestreams:reactive-streams:$reactivestreams_version" implementation "org.reactivestreams:reactive-streams:$reactivestreams_version"
implementation "io.reactivex.rxjava2:rxjava:$rxjava2_version" implementation "io.reactivex.rxjava2:rxjava:$rxjava2_version"
// http://bigbadaboom.github.io/androidsvg/
implementation "com.caverock:androidsvg:$svg_version"
} }

@ -32,3 +32,4 @@ FairEmail uses:
* [POI-HMEF](https://poi.apache.org/components/hmef/index.html). Copyright © 2001-2020 The Apache Software Foundation. [Apache Software License v2](https://poi.apache.org/devel/guidelines.html#The+Licensing). * [POI-HMEF](https://poi.apache.org/components/hmef/index.html). Copyright © 2001-2020 The Apache Software Foundation. [Apache Software License v2](https://poi.apache.org/devel/guidelines.html#The+Licensing).
* [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt). * [GoSquared's Flag Icon Set](https://github.com/gosquared/flags). Copyright (c) 2017 Go Squared Ltd. [MIT License](https://github.com/gosquared/flags/blob/master/LICENSE.txt).
* [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt). * [OpenDyslexic](https://github.com/antijingoist/opendyslexic). Copyright (c) 12/2012 - 2019. Copyright (c) 2019-07-29, Abbie Gonzalez. [SIL Open Font License 1.1](https://github.com/antijingoist/opendyslexic/blob/master/OFL.txt).
* [AndroidSVG](https://github.com/BigBadaboom/androidsvg). Copyright 2013 Paul LeBeau, Cave Rock Software Ltd. [Apache License 2.0](https://github.com/BigBadaboom/androidsvg/blob/master/LICENSE).

@ -38,6 +38,8 @@ import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import com.caverock.androidsvg.SVG;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -701,7 +703,25 @@ public class ContactInfo {
throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage()); throw new FileNotFoundException("Error " + status + ":" + connection.getResponseMessage());
if ("image/svg+xml".equals(type) || url.getPath().endsWith(".svg")) if ("image/svg+xml".equals(type) || url.getPath().endsWith(".svg"))
; // Android does not support SVG try {
SVG svg = SVG.getFromInputStream(connection.getInputStream());
float w = svg.getDocumentWidth();
float h = svg.getDocumentHeight();
if (w < 0 || h < 0) {
w = 1;
h = 1;
}
Bitmap favicon = Bitmap.createBitmap(
scaleToPixels,
Math.round(scaleToPixels * h / w),
Bitmap.Config.ARGB_8888);
favicon.eraseColor(Color.WHITE);
Canvas canvas = new Canvas(favicon);
svg.renderToCanvas(canvas);
return favicon;
} catch (Throwable ex) {
throw new IOException("SVG", ex);
}
Bitmap bitmap = ImageHelper.getScaledBitmap(connection.getInputStream(), url.toString(), scaleToPixels); Bitmap bitmap = ImageHelper.getScaledBitmap(connection.getInputStream(), url.toString(), scaleToPixels);
if (bitmap == null) if (bitmap == null)

Loading…
Cancel
Save