127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler/* 227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * Copyright (C) 2016 The Android Open Source Project 327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * 427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * except in compliance with the License. You may obtain a copy of the License at 627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * 727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * http://www.apache.org/licenses/LICENSE-2.0 827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * 927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * Unless required by applicable law or agreed to in writing, software distributed under the 1027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * KIND, either express or implied. See the License for the specific language governing 1227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler * permissions and limitations under the License. 1327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler */ 1427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 1527a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerpackage com.android.egg.neko; 1627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 1727a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.app.Notification; 1827a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.app.PendingIntent; 1927a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.content.Context; 2027a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.content.Intent; 2127a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.content.res.Resources; 2227a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.graphics.*; 2327a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.graphics.drawable.Drawable; 2427a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.graphics.drawable.Icon; 2527a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport android.os.Bundle; 2627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 2727a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport java.util.Random; 2827a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport java.util.concurrent.ThreadLocalRandom; 2927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 3027a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerimport com.android.egg.R; 3127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 3227a9fcc61823f919cee773df563b49ee11004f3bDan Sandlerpublic class Cat extends Drawable { 33610f6ede251c44cb4cf0e8a993d8d88c121159f9Dan Sandler public static final long[] PURR = {0, 40, 20, 40, 20, 40, 20, 40, 20, 40, 20, 40}; 34610f6ede251c44cb4cf0e8a993d8d88c121159f9Dan Sandler 3527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private Random mNotSoRandom; 3627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private Bitmap mBitmap; 3727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private long mSeed; 3827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private String mName; 3927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private int mBodyColor; 4027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 4127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private synchronized Random notSoRandom(long seed) { 4227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (mNotSoRandom == null) { 4327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler mNotSoRandom = new Random(); 4427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler mNotSoRandom.setSeed(seed); 4527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 4627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return mNotSoRandom; 4727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 4827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 4927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static final float frandrange(Random r, float a, float b) { 5027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return (b-a)*r.nextFloat() + a; 5127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 5227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 5327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static final Object choose(Random r, Object...l) { 5427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return l[r.nextInt(l.length)]; 5527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 5627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 5727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static final int chooseP(Random r, int[] a) { 5827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler int pct = r.nextInt(1000); 5927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int stop = a.length-2; 6027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler int i=0; 6127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler while (i<stop) { 6227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler pct -= a[i]; 6327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (pct < 0) break; 6427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler i+=2; 6527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 6627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return a[i+1]; 6727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 6827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 6927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static final int[] P_BODY_COLORS = { 7027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 180, 0xFF212121, // black 7127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 180, 0xFFFFFFFF, // white 7227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 140, 0xFF616161, // gray 7327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 140, 0xFF795548, // brown 7427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 100, 0xFF90A4AE, // steel 7527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 100, 0xFFFFF9C4, // buff 7627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 100, 0xFFFF8F00, // orange 7727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 5, 0xFF29B6F6, // blue..? 7827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 5, 0xFFFFCDD2, // pink!? 7927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 5, 0xFFCE93D8, // purple?!?!? 8027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 4, 0xFF43A047, // yeah, why not green 8127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 1, 0, // ?!?!?! 8227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler }; 8327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 8427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static final int[] P_COLLAR_COLORS = { 8527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 250, 0xFFFFFFFF, 8627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 250, 0xFF000000, 8727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 250, 0xFFF44336, 8827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 50, 0xFF1976D2, 8927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 50, 0xFFFDD835, 9027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 50, 0xFFFB8C00, 9127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 50, 0xFFF48FB1, 9227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 50, 0xFF4CAF50, 9327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler }; 9427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 9527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static final int[] P_BELLY_COLORS = { 9627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 750, 0, 9727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 250, 0xFFFFFFFF, 9827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler }; 9927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 10027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static final int[] P_DARK_SPOT_COLORS = { 10127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 700, 0, 10227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 250, 0xFF212121, 10327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 50, 0xFF6D4C41, 10427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler }; 10527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 10627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static final int[] P_LIGHT_SPOT_COLORS = { 10727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 700, 0, 10827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 300, 0xFFFFFFFF, 10927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler }; 11027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 11127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private CatParts D; 11227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 11327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static void tint(int color, Drawable ... ds) { 11427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler for (Drawable d : ds) { 11527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (d != null) { 11627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler d.mutate().setTint(color); 11727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 11827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 11927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 12027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 12127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static boolean isDark(int color) { 12227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int r = (color & 0xFF0000) >> 16; 12327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int g = (color & 0x00FF00) >> 8; 12427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int b = color & 0x0000FF; 12527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return (r + g + b) < 0x80; 12627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 12727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 12827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Cat(Context context, long seed) { 12927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler D = new CatParts(context); 13027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler mSeed = seed; 13127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 13227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler setName(context.getString(R.string.default_cat_name, 13327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler String.valueOf(mSeed).substring(0, 3))); 13427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 13527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final Random nsr = notSoRandom(seed); 13627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 13727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler // body color 13827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler mBodyColor = chooseP(nsr, P_BODY_COLORS); 13927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (mBodyColor == 0) mBodyColor = Color.HSVToColor(new float[] { 14027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler nsr.nextFloat()*360f, frandrange(nsr,0.5f,1f), frandrange(nsr,0.5f, 1f)}); 14127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 14227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(mBodyColor, D.body, D.head, D.leg1, D.leg2, D.leg3, D.leg4, D.tail, 14327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler D.leftEar, D.rightEar, D.foot1, D.foot2, D.foot3, D.foot4, D.tailCap); 14427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(0x20000000, D.leg2Shadow, D.tailShadow); 14527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (isDark(mBodyColor)) { 14627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(0xFFFFFFFF, D.leftEye, D.rightEye, D.mouth, D.nose); 14727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 14827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(isDark(mBodyColor) ? 0xFFEF9A9A : 0x20D50000, D.leftEarInside, D.rightEarInside); 14927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 15027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(chooseP(nsr, P_BELLY_COLORS), D.belly); 15127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(chooseP(nsr, P_BELLY_COLORS), D.back); 15227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int faceColor = chooseP(nsr, P_BELLY_COLORS); 15327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(faceColor, D.faceSpot); 15427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (!isDark(faceColor)) { 15527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(0xFF000000, D.mouth, D.nose); 15627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 15727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 15827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (nsr.nextFloat() < 0.25f) { 15927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(0xFFFFFFFF, D.foot1, D.foot2, D.foot3, D.foot4); 16027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } else { 16127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (nsr.nextFloat() < 0.25f) { 16227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(0xFFFFFFFF, D.foot1, D.foot2); 16327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } else if (nsr.nextFloat() < 0.25f) { 16427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(0xFFFFFFFF, D.foot3, D.foot4); 16527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } else if (nsr.nextFloat() < 0.1f) { 16627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(0xFFFFFFFF, (Drawable) choose(nsr, D.foot1, D.foot2, D.foot3, D.foot4)); 16727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 16827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 16927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 17027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(nsr.nextFloat() < 0.333f ? 0xFFFFFFFF : mBodyColor, D.tailCap); 17127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 17227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int capColor = chooseP(nsr, isDark(mBodyColor) ? P_LIGHT_SPOT_COLORS : P_DARK_SPOT_COLORS); 17327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(capColor, D.cap); 17427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler //tint(chooseP(nsr, isDark(bodyColor) ? P_LIGHT_SPOT_COLORS : P_DARK_SPOT_COLORS), D.nose); 17527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 17627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int collarColor = chooseP(nsr, P_COLLAR_COLORS); 17727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint(collarColor, D.collar); 17827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tint((nsr.nextFloat() < 0.1f) ? collarColor : 0, D.bowtie); 17927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 18027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 18127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static Cat create(Context context) { 18227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return new Cat(context, Math.abs(ThreadLocalRandom.current().nextInt())); 18327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 18427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 18527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Notification.Builder buildNotification(Context context) { 18627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final Bundle extras = new Bundle(); 18727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler extras.putString("android.substName", context.getString(R.string.notification_name)); 18827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final Intent intent = new Intent(Intent.ACTION_MAIN) 18927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setClass(context, NekoLand.class) 19027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 19127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return new Notification.Builder(context) 19227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setSmallIcon(Icon.createWithResource(context, R.drawable.stat_icon)) 19327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setLargeIcon(createLargeIcon(context)) 19427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setColor(getBodyColor()) 19527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setPriority(Notification.PRIORITY_LOW) 19627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setContentTitle(context.getString(R.string.notification_title)) 19727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setShowWhen(true) 19827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setCategory(Notification.CATEGORY_STATUS) 19927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setContentText(getName()) 20027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) 20127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .setAutoCancel(true) 202610f6ede251c44cb4cf0e8a993d8d88c121159f9Dan Sandler .setVibrate(PURR) 20327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler .addExtras(extras); 20427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 20527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 20627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public long getSeed() { 20727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return mSeed; 20827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 20927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 21027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler @Override 21127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public void draw(Canvas canvas) { 21227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int w = Math.min(canvas.getWidth(), canvas.getHeight()); 21327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int h = w; 21427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 21527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (mBitmap == null || mBitmap.getWidth() != w || mBitmap.getHeight() != h) { 21627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 21727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final Canvas bitCanvas = new Canvas(mBitmap); 21827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler slowDraw(bitCanvas, 0, 0, w, h); 21927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 22027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler canvas.drawBitmap(mBitmap, 0, 0, null); 22127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 22227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 22327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private void slowDraw(Canvas canvas, int x, int y, int w, int h) { 22427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler for (int i = 0; i < D.drawingOrder.length; i++) { 22527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final Drawable d = D.drawingOrder[i]; 22627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (d != null) { 22727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler d.setBounds(x, y, x+w, y+h); 22827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler d.draw(canvas); 22927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 23027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 23127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 23227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 23327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 23427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Bitmap createBitmap(int w, int h) { 23527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler if (mBitmap != null && mBitmap.getWidth() == w && mBitmap.getHeight() == h) { 23627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return mBitmap.copy(mBitmap.getConfig(), true); 23727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 23827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 23927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler slowDraw(new Canvas(result), 0, 0, w, h); 24027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return result; 24127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 24227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 24327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Icon createLargeIcon(Context context) { 24427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final Resources res = context.getResources(); 24527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int w = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); 24627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final int h = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); 24727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 24827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 24927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final Canvas canvas = new Canvas(result); 25027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler final Paint pt = new Paint(); 25127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler float[] hsv = new float[3]; 25227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler Color.colorToHSV(mBodyColor, hsv); 25327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler hsv[2] = (hsv[2]>0.5f) 25427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler ? (hsv[2] - 0.25f) 25527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler : (hsv[2] + 0.25f); 25627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler pt.setColor(Color.HSVToColor(hsv)); 25727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler float r = w/2; 25827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler canvas.drawCircle(r, r, r, pt); 25927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler int m = w/10; 26027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 26127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler slowDraw(canvas, m, m, w-m-m, h-m-m); 26227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 26327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return Icon.createWithBitmap(result); 26427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 26527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 26627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler @Override 26727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public void setAlpha(int i) { 26827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 26927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 27027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 27127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler @Override 27227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public void setColorFilter(ColorFilter colorFilter) { 27327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 27427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 27527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 27627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler @Override 27727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public int getOpacity() { 27827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return PixelFormat.TRANSLUCENT; 27927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 28027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 28127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public String getName() { 28227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return mName; 28327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 28427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 28527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public void setName(String name) { 28627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler this.mName = name; 28727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 28827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 28927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public int getBodyColor() { 29027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return mBodyColor; 29127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 29227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 29327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public static class CatParts { 29427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable leftEar; 29527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable rightEar; 29627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable rightEarInside; 29727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable leftEarInside; 29827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable head; 29927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable faceSpot; 30027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable cap; 30127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable mouth; 30227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable body; 30327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable foot1; 30427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable leg1; 30527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable foot2; 30627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable leg2; 30727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable foot3; 30827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable leg3; 30927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable foot4; 31027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable leg4; 31127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable tail; 31227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable leg2Shadow; 31327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable tailShadow; 31427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable tailCap; 31527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable belly; 31627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable back; 31727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable rightEye; 31827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable leftEye; 31927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable nose; 32027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable bowtie; 32127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable collar; 32227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public Drawable[] drawingOrder; 32327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler 32427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler public CatParts(Context context) { 32527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler body = context.getDrawable(R.drawable.body); 32627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler head = context.getDrawable(R.drawable.head); 32727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leg1 = context.getDrawable(R.drawable.leg1); 32827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leg2 = context.getDrawable(R.drawable.leg2); 32927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leg3 = context.getDrawable(R.drawable.leg3); 33027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leg4 = context.getDrawable(R.drawable.leg4); 33127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tail = context.getDrawable(R.drawable.tail); 33227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leftEar = context.getDrawable(R.drawable.left_ear); 33327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler rightEar = context.getDrawable(R.drawable.right_ear); 33427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler rightEarInside = context.getDrawable(R.drawable.right_ear_inside); 33527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leftEarInside = context.getDrawable(R.drawable.left_ear_inside); 33627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler faceSpot = context.getDrawable(R.drawable.face_spot); 33727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler cap = context.getDrawable(R.drawable.cap); 33827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler mouth = context.getDrawable(R.drawable.mouth); 33927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler foot4 = context.getDrawable(R.drawable.foot4); 34027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler foot3 = context.getDrawable(R.drawable.foot3); 34127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler foot1 = context.getDrawable(R.drawable.foot1); 34227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler foot2 = context.getDrawable(R.drawable.foot2); 34327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leg2Shadow = context.getDrawable(R.drawable.leg2_shadow); 34427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tailShadow = context.getDrawable(R.drawable.tail_shadow); 34527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tailCap = context.getDrawable(R.drawable.tail_cap); 34627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler belly = context.getDrawable(R.drawable.belly); 34727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler back = context.getDrawable(R.drawable.back); 34827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler rightEye = context.getDrawable(R.drawable.right_eye); 34927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leftEye = context.getDrawable(R.drawable.left_eye); 35027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler nose = context.getDrawable(R.drawable.nose); 35127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler collar = context.getDrawable(R.drawable.collar); 35227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler bowtie = context.getDrawable(R.drawable.bowtie); 35327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler drawingOrder = getDrawingOrder(); 35427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 35527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler private Drawable[] getDrawingOrder() { 35627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler return new Drawable[] { 35727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler collar, 35827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leftEar, leftEarInside, rightEar, rightEarInside, 35927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler head, 36027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler faceSpot, 36127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler cap, 36227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leftEye, rightEye, 36327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler nose, mouth, 36427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler tail, tailCap, tailShadow, 36527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler foot1, leg1, 36627a9fcc61823f919cee773df563b49ee11004f3bDan Sandler foot2, leg2, 36727a9fcc61823f919cee773df563b49ee11004f3bDan Sandler foot3, leg3, 36827a9fcc61823f919cee773df563b49ee11004f3bDan Sandler foot4, leg4, 36927a9fcc61823f919cee773df563b49ee11004f3bDan Sandler leg2Shadow, 37027a9fcc61823f919cee773df563b49ee11004f3bDan Sandler body, belly, 37127a9fcc61823f919cee773df563b49ee11004f3bDan Sandler bowtie 37227a9fcc61823f919cee773df563b49ee11004f3bDan Sandler }; 37327a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 37427a9fcc61823f919cee773df563b49ee11004f3bDan Sandler } 37527a9fcc61823f919cee773df563b49ee11004f3bDan Sandler} 376