Welcome to mirror list, hosted at ThFree Co, Russian Federation.

IconUtils.java « utils « wolfi « es « java « main « src « app - github.com/nextcloud/passman-android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc346b061cedba243125e75056d69bf63fae9f0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package es.wolfi.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.PictureDrawable;
import android.util.Base64;
import android.widget.ImageView;

import com.caverock.androidsvg.SVG;
import com.caverock.androidsvg.SVGParseException;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayInputStream;

import es.wolfi.app.passman.R;

public class IconUtils {
    public static void loadIconToImageView(String favicon, ImageView credentialIconImageView) {
        credentialIconImageView.setImageResource(R.drawable.ic_baseline_lock_24);
        if (favicon != null && !favicon.equals("") && !favicon.equals("null")) {
            try {
                JSONObject icon = new JSONObject(favicon);
                if (!icon.getString("type").equals("false") && !icon.getString("content").equals("")) {
                    byte[] byteImageData = Base64.decode(icon.getString("content"), Base64.DEFAULT);
                    Bitmap bitmapImageData = BitmapFactory.decodeByteArray(byteImageData, 0, byteImageData.length);
                    if (bitmapImageData != null) {
                        credentialIconImageView.setImageBitmap(bitmapImageData);
                    } else if (icon.getString("type").equals("svg+xml")) {
                        SVG svg = SVG.getFromInputStream(new ByteArrayInputStream(byteImageData));
                        credentialIconImageView.setImageDrawable(new PictureDrawable(svg.renderToPicture()));
                    }
                }
            } catch (JSONException | SVGParseException e) {
                e.printStackTrace();
            }
        }
    }
}