Use a compressed Icon for the notification's largeIcon.
Fixes: 29918548 Change-Id: I2f70011221c7ec96aab8e540cd0213660282b49c
This commit is contained in:
committed by
Daniel Sandler
parent
4a1bcd966b
commit
1e52909888
19
packages/EasterEgg/res/values/dimens.xml
Normal file
19
packages/EasterEgg/res/values/dimens.xml
Normal file
@@ -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>
|
||||||
@@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
@@ -208,7 +209,7 @@ public class Cat extends Drawable {
|
|||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
return new Notification.Builder(context)
|
return new Notification.Builder(context)
|
||||||
.setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon))
|
.setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon))
|
||||||
.setLargeIcon(createLargeIcon(context))
|
.setLargeIcon(createNotificationLargeIcon(context))
|
||||||
.setColor(getBodyColor())
|
.setColor(getBodyColor())
|
||||||
.setPriority(Notification.PRIORITY_LOW)
|
.setPriority(Notification.PRIORITY_LOW)
|
||||||
.setContentTitle(context.getString(R.string.notification_title))
|
.setContentTitle(context.getString(R.string.notification_title))
|
||||||
@@ -258,11 +259,24 @@ public class Cat extends Drawable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Icon createLargeIcon(Context context) {
|
public static Icon recompressIcon(Icon bitmapIcon) {
|
||||||
final Resources res = context.getResources();
|
if (bitmapIcon.getType() != Icon.TYPE_BITMAP) return bitmapIcon;
|
||||||
final int w = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
|
final Bitmap bits = bitmapIcon.getBitmap();
|
||||||
final int h = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
|
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 = 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);
|
Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
||||||
final Canvas canvas = new Canvas(result);
|
final Canvas canvas = new Canvas(result);
|
||||||
final Paint pt = new Paint();
|
final Paint pt = new Paint();
|
||||||
|
|||||||
@@ -148,7 +148,9 @@ public class NekoLand extends Activity implements PrefsListener {
|
|||||||
final EditText text = (EditText) view.findViewById(android.R.id.edit);
|
final EditText text = (EditText) view.findViewById(android.R.id.edit);
|
||||||
text.setText(cat.getName());
|
text.setText(cat.getName());
|
||||||
text.setSelection(cat.getName().length());
|
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)
|
new AlertDialog.Builder(context)
|
||||||
.setTitle(" ")
|
.setTitle(" ")
|
||||||
.setIcon(catIcon)
|
.setIcon(catIcon)
|
||||||
@@ -211,7 +213,8 @@ public class NekoLand extends Activity implements PrefsListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final CatHolder holder, int position) {
|
public void onBindViewHolder(final CatHolder holder, int position) {
|
||||||
Context context = holder.itemView.getContext();
|
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.textView.setText(mCats[position].getName());
|
||||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user