Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e529098 authored by Dan Sandler's avatar Dan Sandler Committed by Daniel Sandler
Browse files

Use a compressed Icon for the notification's largeIcon.

Fixes: 29918548
Change-Id: I2f70011221c7ec96aab8e540cd0213660282b49c
parent 4a1bcd96
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project

   Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <dimen name="neko_display_size">64dp</dimen>
</resources>
+18 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;

import java.io.ByteArrayOutputStream;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

@@ -208,7 +209,7 @@ public class Cat extends Drawable {
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        return new Notification.Builder(context)
                .setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon))
                .setLargeIcon(createLargeIcon(context))
                .setLargeIcon(createNotificationLargeIcon(context))
                .setColor(getBodyColor())
                .setPriority(Notification.PRIORITY_LOW)
                .setContentTitle(context.getString(R.string.notification_title))
@@ -258,11 +259,24 @@ public class Cat extends Drawable {
        return result;
    }

    public Icon createLargeIcon(Context context) {
    public static Icon recompressIcon(Icon bitmapIcon) {
        if (bitmapIcon.getType() != Icon.TYPE_BITMAP) return bitmapIcon;
        final Bitmap bits = bitmapIcon.getBitmap();
        final ByteArrayOutputStream ostream = new ByteArrayOutputStream(
                bits.getWidth() * bits.getHeight() * 2); // guess 50% compression
        final boolean ok = bits.compress(Bitmap.CompressFormat.PNG, 100, ostream);
        if (!ok) return null;
        return Icon.createWithData(ostream.toByteArray(), 0, ostream.size());
    }

    public Icon createNotificationLargeIcon(Context context) {
        final Resources res = context.getResources();
        final int w = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
        final int h = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        final int w = 2*res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
        final int h = 2*res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        return recompressIcon(createIcon(context, w, h));
    }

    public Icon createIcon(Context context, int w, int h) {
        Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(result);
        final Paint pt = new Paint();
+5 −2
Original line number Diff line number Diff line
@@ -148,7 +148,9 @@ public class NekoLand extends Activity implements PrefsListener {
        final EditText text = (EditText) view.findViewById(android.R.id.edit);
        text.setText(cat.getName());
        text.setSelection(cat.getName().length());
        Drawable catIcon = cat.createLargeIcon(this).loadDrawable(this);
        final int size = context.getResources()
                .getDimensionPixelSize(android.R.dimen.app_icon_size);
        Drawable catIcon = cat.createIcon(this, size, size).loadDrawable(this);
        new AlertDialog.Builder(context)
                .setTitle(" ")
                .setIcon(catIcon)
@@ -211,7 +213,8 @@ public class NekoLand extends Activity implements PrefsListener {
        @Override
        public void onBindViewHolder(final CatHolder holder, int position) {
            Context context = holder.itemView.getContext();
            holder.imageView.setImageIcon(mCats[position].createLargeIcon(context));
            final int size = context.getResources().getDimensionPixelSize(R.dimen.neko_display_size);
            holder.imageView.setImageIcon(mCats[position].createIcon(context, size, size));
            holder.textView.setText(mCats[position].getName());
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override