summaryrefslogtreecommitdiff
path: root/packages/EasterEgg
diff options
context:
space:
mode:
authorDan Sandler <dsandler@android.com>2016-07-16 01:01:19 -0400
committerDaniel Sandler <dsandler@android.com>2016-07-24 21:22:23 +0000
commit1e52909888fc27bc8d7f63ceeabba0a87b65e419 (patch)
tree6848f4b613273da4a33997f93dfd724fc0e69d18 /packages/EasterEgg
parent4a1bcd966b1c271909f38b41031cc012e233fbdd (diff)
Use a compressed Icon for the notification's largeIcon.
Fixes: 29918548 Change-Id: I2f70011221c7ec96aab8e540cd0213660282b49c
Diffstat (limited to 'packages/EasterEgg')
-rw-r--r--packages/EasterEgg/res/values/dimens.xml19
-rw-r--r--packages/EasterEgg/src/com/android/egg/neko/Cat.java22
-rw-r--r--packages/EasterEgg/src/com/android/egg/neko/NekoLand.java7
3 files changed, 42 insertions, 6 deletions
diff --git a/packages/EasterEgg/res/values/dimens.xml b/packages/EasterEgg/res/values/dimens.xml
new file mode 100644
index 000000000000..e9dcebd27f7b
--- /dev/null
+++ b/packages/EasterEgg/res/values/dimens.xml
@@ -0,0 +1,19 @@
+<?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>
diff --git a/packages/EasterEgg/src/com/android/egg/neko/Cat.java b/packages/EasterEgg/src/com/android/egg/neko/Cat.java
index 2793468562ba..d20e9c7fd1ed 100644
--- a/packages/EasterEgg/src/com/android/egg/neko/Cat.java
+++ b/packages/EasterEgg/src/com/android/egg/neko/Cat.java
@@ -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();
diff --git a/packages/EasterEgg/src/com/android/egg/neko/NekoLand.java b/packages/EasterEgg/src/com/android/egg/neko/NekoLand.java
index c6b7640d00dd..f59f0d97d24b 100644
--- a/packages/EasterEgg/src/com/android/egg/neko/NekoLand.java
+++ b/packages/EasterEgg/src/com/android/egg/neko/NekoLand.java
@@ -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