From e64c833ff9f4f063a7aca50007f29db29ab0b722 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Fri, 13 Nov 2009 18:22:25 -0800 Subject: [PATCH] Improvements to the Nexus pulse effect. Added a faint glow, faster pulses, and a large pulse effect when icons are dropped. Equalized apparent luminosity across Google brand colors by tweaking alpha. Reduced slightly the zag probability. Change-Id: I3faf1a043e4f6dec5dac0d121ab30e346124eb69 --- .../android/wallpaper/nexus/NexusWallpaper.java | 99 ++++++++++++++++++++-- 1 file changed, 90 insertions(+), 9 deletions(-) diff --git a/src/com/android/wallpaper/nexus/NexusWallpaper.java b/src/com/android/wallpaper/nexus/NexusWallpaper.java index 01059eb..b393616 100644 --- a/src/com/android/wallpaper/nexus/NexusWallpaper.java +++ b/src/com/android/wallpaper/nexus/NexusWallpaper.java @@ -19,11 +19,14 @@ package com.android.wallpaper.nexus; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.BlurMaskFilter; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.LightingColorFilter; import android.graphics.Paint; import android.graphics.Point; import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; @@ -42,19 +45,19 @@ import com.android.wallpaper.R; public class NexusWallpaper extends WallpaperService { - private static final int NUM_PULSES = 18; - private static final int MAX_PULSES = 42; + private static final int NUM_PULSES = 12; + private static final int MAX_PULSES = 32; private static final int PULSE_SIZE = 16; - private static final int MAX_ALPHA = 192; // 0..255 + private static final int MAX_ALPHA = 128; // 0..255 private static final int PULSE_DELAY = 5000; // random restart time, in ms private static final float ALPHA_DECAY = 0.85f; private static final boolean ACCEPTS_TAP = true; - private static final int ANIMATION_PERIOD = 1000/30; // in ms^-1 + private static final int ANIMATION_PERIOD = 1000/50; // in ms^-1 private static final int[] PULSE_COLORS = { - 0xFF0066CC, 0xFFFF0000, 0xFFFFCC00, 0xFF009900, + 0xFF0066CC, 0xDDFF0000, 0xBBFFCC00, 0xEE009900, }; private static final String LOG_TAG = "Nexus"; @@ -77,10 +80,11 @@ public class NexusWallpaper extends WallpaperService { Point[] pts; int start, len; // pointers into pts Paint paint; + Paint glowPaint; long startTime; boolean started; - public float zagProb = 0.01f; + public float zagProb = 0.007f; public int speed = 1; public Pulse() { @@ -92,6 +96,9 @@ public class NexusWallpaper extends WallpaperService { paint = new Paint(Paint.FILTER_BITMAP_FLAG|Paint.DITHER_FLAG); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); + glowPaint = new Paint(paint); + glowPaint.setAlpha((int)(MAX_ALPHA*0.7f)); + start = len = 0; } public Pulse(long now, int x, int y, int dx, int dy) { @@ -126,10 +133,15 @@ public class NexusWallpaper extends WallpaperService { v.x = dx; v.y = dy; startTime = now; - paint.setColor(PULSE_COLORS[(int)Math.floor(Math.random()*PULSE_COLORS.length)]); + setColor(PULSE_COLORS[(int)Math.floor(Math.random()*PULSE_COLORS.length)]); started = false; } + public void setColor(int c) { + paint.setColor(c); + glowPaint.setColorFilter(new LightingColorFilter(paint.getColor(), 0)); + } + public void startRandomEdge(long now, boolean diag) { int x, y; if (Math.random() < 0.5) { @@ -166,7 +178,7 @@ public class NexusWallpaper extends WallpaperService { int color = Color.HSVToColor(hsv); */ // select colors - paint.setColor(PULSE_COLORS[(int)Math.floor(Math.random()*PULSE_COLORS.length)]); + setColor(PULSE_COLORS[(int)Math.floor(Math.random()*PULSE_COLORS.length)]); started = false; } @@ -199,6 +211,10 @@ public class NexusWallpaper extends WallpaperService { if (!started) return; boolean onScreen = false; int a = MAX_ALPHA; + + Point head = getHead(); + c.drawBitmap(mGlow, (head.x-1)*mCellSize, (head.y-1)*mCellSize, glowPaint); + final Rect r = new Rect(0, 0, mCellSize, mCellSize); for (int i=len-1; i>=0; i--) { paint.setAlpha(a); @@ -211,6 +227,7 @@ public class NexusWallpaper extends WallpaperService { onScreen = !(p.x < 0 || p.x > mColumnCount || p.y < 0 || p.y > mRowCount); } + if (!onScreen) { // Time to die. recycleOrRemovePulse(this); @@ -232,6 +249,8 @@ public class NexusWallpaper extends WallpaperService { private Bitmap mBackground; private Bitmap mGreenLed; + + private Bitmap mGlow; private Set mPulses = new HashSet(); private Set mDeadPulses = new HashSet(); @@ -262,6 +281,14 @@ public class NexusWallpaper extends WallpaperService { mCellSize = mGreenLed.getWidth(); + mGlow = Bitmap.createBitmap(3*mCellSize, 3*mCellSize, Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(mGlow); + Paint p = new Paint(); + final int halfCell = mCellSize/2; + p.setMaskFilter(new BlurMaskFilter(halfCell, BlurMaskFilter.Blur.NORMAL)); + p.setColor(Color.WHITE); + c.drawRect(halfCell, halfCell, 5*halfCell, 5*halfCell, p); + initializeState(); if (isPreview()) { @@ -344,24 +371,78 @@ public class NexusWallpaper extends WallpaperService { final int bw = mBackgroundWidth; final int cellX = (int)((x + mOffsetX * (bw-dw)) / mCellSize); final int cellY = (int)(y / mCellSize); + + int colorIdx = (int)(Math.random() * PULSE_COLORS.length); + Pulse p = new Pulse(); p.zagProb = 0; p.start(0, cellX, cellY, 0, 1); + p.setColor(PULSE_COLORS[colorIdx]); addPulse(p); + colorIdx = (colorIdx + 1) % PULSE_COLORS.length; + p = new Pulse(); p.zagProb = 0; p.start(0, cellX, cellY, 1, 0); + p.setColor(PULSE_COLORS[colorIdx]); addPulse(p); + colorIdx = (colorIdx + 1) % PULSE_COLORS.length; + p = new Pulse(); p.zagProb = 0; p.start(0, cellX, cellY, -1, 0); + p.setColor(PULSE_COLORS[colorIdx]); addPulse(p); + colorIdx = (colorIdx + 1) % PULSE_COLORS.length; + p = new Pulse(); p.zagProb = 0; p.start(0, cellX, cellY, 0, -1); + p.setColor(PULSE_COLORS[colorIdx]); addPulse(p); + colorIdx = (colorIdx + 1) % PULSE_COLORS.length; + } else if ("android.home.drop".equals(action)) { - // TODO: something awesome + final SurfaceHolder holder = getSurfaceHolder(); + final Rect frame = holder.getSurfaceFrame(); + + final int dw = frame.width(); + final int bw = mBackgroundWidth; + final int cellX = (int)((x + mOffsetX * (bw-dw)) / mCellSize); + final int cellY = (int)(y / mCellSize); + Pulse p = new Pulse(); + p.zagProb = 0; + p.start(0, cellX, cellY, 0, 1); + addPulse(p); + p = new Pulse(); + p.zagProb = 0; + p.start(0, cellX, cellY, 1, 0); + addPulse(p); + p = new Pulse(); + p.zagProb = 0; + p.start(0, cellX, cellY, -1, 0); + addPulse(p); + p = new Pulse(); + p.zagProb = 0; + p.start(0, cellX, cellY, 0, -1); + addPulse(p); + + p = new Pulse(); + p.zagProb = 0; + p.start(0, cellX, cellY, -1, -1); + addPulse(p); + p = new Pulse(); + p.zagProb = 0; + p.start(0, cellX, cellY, 1, -1); + addPulse(p); + p = new Pulse(); + p.zagProb = 0; + p.start(0, cellX, cellY, 1, 1); + addPulse(p); + p = new Pulse(); + p.zagProb = 0; + p.start(0, cellX, cellY, -1, 1); + addPulse(p); } return null; } -- 2.11.0