Search in sources :

Example 1 with SvgOrImageBitmapTranscoder

use of com.owncloud.android.utils.svg.SvgOrImageBitmapTranscoder in project android by nextcloud.

the class DrawerActivity method updateHeader.

public void updateHeader() {
    if (getAccount() != null && getStorageManager().getCapability(getAccount().name).getServerBackground() != null) {
        OCCapability capability = getStorageManager().getCapability(getAccount().name);
        String logo = capability.getServerLogo();
        int primaryColor = ThemeColorUtils.primaryColor(getAccount(), false, this);
        // set background to primary color
        LinearLayout drawerHeader = mNavigationViewHeader.findViewById(R.id.drawer_header_view);
        drawerHeader.setBackgroundColor(ThemeColorUtils.unchangedPrimaryColor(getAccount(), this));
        if (!TextUtils.isEmpty(logo) && URLUtil.isValidUrl(logo)) {
            // background image
            GenericRequestBuilder<Uri, InputStream, SVGorImage, Bitmap> requestBuilder = Glide.with(this).using(Glide.buildStreamModelLoader(Uri.class, this), InputStream.class).from(Uri.class).as(SVGorImage.class).transcode(new SvgOrImageBitmapTranscoder(128, 128), Bitmap.class).sourceEncoder(new StreamEncoder()).cacheDecoder(new FileToStreamDecoder<>(new SvgOrImageDecoder())).decoder(new SvgOrImageDecoder());
            // background image
            SimpleTarget target = new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                    Bitmap logo = resource;
                    int width = resource.getWidth();
                    int height = resource.getHeight();
                    int max = Math.max(width, height);
                    if (max > MAX_LOGO_SIZE_PX) {
                        logo = BitmapUtils.scaleBitmap(resource, MAX_LOGO_SIZE_PX, width, height, max);
                    }
                    Drawable[] drawables = { new ColorDrawable(primaryColor), new BitmapDrawable(logo) };
                    LayerDrawable layerDrawable = new LayerDrawable(drawables);
                    String name = capability.getServerName();
                    setDrawerHeaderLogo(layerDrawable, name);
                }
            };
            requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE).load(Uri.parse(logo)).into(target);
        }
    }
}
Also used : SVGorImage(com.owncloud.android.utils.svg.SVGorImage) FileToStreamDecoder(com.bumptech.glide.load.resource.file.FileToStreamDecoder) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) InputStream(java.io.InputStream) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) Uri(android.net.Uri) MenuSimpleTarget(com.owncloud.android.utils.svg.MenuSimpleTarget) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) SvgOrImageDecoder(com.owncloud.android.utils.svg.SvgOrImageDecoder) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) SvgOrImageBitmapTranscoder(com.owncloud.android.utils.svg.SvgOrImageBitmapTranscoder) LinearLayout(android.widget.LinearLayout) StreamEncoder(com.bumptech.glide.load.model.StreamEncoder)

Aggregations

Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1 Uri (android.net.Uri)1 LinearLayout (android.widget.LinearLayout)1 StreamEncoder (com.bumptech.glide.load.model.StreamEncoder)1 FileToStreamDecoder (com.bumptech.glide.load.resource.file.FileToStreamDecoder)1 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)1 MenuSimpleTarget (com.owncloud.android.utils.svg.MenuSimpleTarget)1 SVGorImage (com.owncloud.android.utils.svg.SVGorImage)1 SvgOrImageBitmapTranscoder (com.owncloud.android.utils.svg.SvgOrImageBitmapTranscoder)1 SvgOrImageDecoder (com.owncloud.android.utils.svg.SvgOrImageDecoder)1 InputStream (java.io.InputStream)1