blob: b537f7accb1e51e08946a798e925e66d9f721f24 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Winson Chung97d85d22011-04-13 11:27:36 -070019import java.util.Random;
20
Winson Chungaafa03c2010-06-11 17:34:16 -070021import android.content.Context;
22import android.content.res.Resources;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.graphics.Bitmap;
Joe Onorato1291a8c2009-09-15 15:07:25 -040024import android.graphics.BlurMaskFilter;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025import android.graphics.Canvas;
Joe Onorato56d82912010-03-07 14:32:10 -050026import android.graphics.ColorMatrix;
27import android.graphics.ColorMatrixColorFilter;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.graphics.Paint;
Joe Onoratobf15cb42009-08-07 14:33:40 -070029import android.graphics.PaintFlagsDrawFilter;
Joe Onorato1291a8c2009-09-15 15:07:25 -040030import android.graphics.PorterDuff;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.graphics.Rect;
Joe Onoratobf15cb42009-08-07 14:33:40 -070032import android.graphics.RectF;
Mike Reedcdd11792009-10-29 17:27:55 -040033import android.graphics.TableMaskFilter;
Joe Onoratobf15cb42009-08-07 14:33:40 -070034import android.graphics.Typeface;
Winson Chungaafa03c2010-06-11 17:34:16 -070035import android.graphics.drawable.BitmapDrawable;
36import android.graphics.drawable.Drawable;
37import android.graphics.drawable.PaintDrawable;
Joe Onoratobf15cb42009-08-07 14:33:40 -070038import android.text.StaticLayout;
39import android.text.TextPaint;
Winson Chungaafa03c2010-06-11 17:34:16 -070040import android.text.Layout.Alignment;
Dianne Hackborn32ce7f12009-07-22 21:56:50 -070041import android.util.DisplayMetrics;
Joe Onoratobf15cb42009-08-07 14:33:40 -070042import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043
Romain Guyedcce092010-03-04 13:03:17 -080044import com.android.launcher.R;
45
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046/**
47 * Various utilities shared amongst the Launcher's classes.
48 */
49final class Utilities {
Joe Onorato1291a8c2009-09-15 15:07:25 -040050 private static final String TAG = "Launcher.Utilities";
51
Joe Onorato9392a752009-09-15 17:13:09 -040052 private static final boolean TEXT_BURN = false;
53
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054 private static int sIconWidth = -1;
55 private static int sIconHeight = -1;
Michael Jurka7ef959b2011-02-23 11:48:32 -080056 private static int sIconContentSize = -1;
Joe Onorato6665c0f2009-09-02 15:27:24 -070057 private static int sIconTextureWidth = -1;
58 private static int sIconTextureHeight = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059
Joe Onorato1291a8c2009-09-15 15:07:25 -040060 private static final Paint sBlurPaint = new Paint();
Joe Onoratoeb8325a2009-11-08 13:20:30 -050061 private static final Paint sGlowColorPressedPaint = new Paint();
Joe Onoratoc61cff92009-11-08 11:54:39 -050062 private static final Paint sGlowColorFocusedPaint = new Paint();
Joe Onorato56d82912010-03-07 14:32:10 -050063 private static final Paint sDisabledPaint = new Paint();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064 private static final Rect sOldBounds = new Rect();
Romain Guy89911d22009-09-28 18:48:49 -070065 private static final Canvas sCanvas = new Canvas();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066
67 static {
68 sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG,
69 Paint.FILTER_BITMAP_FLAG));
70 }
Joe Onorato6665c0f2009-09-02 15:27:24 -070071 static int sColors[] = { 0xffff0000, 0xff00ff00, 0xff0000ff };
72 static int sColorIndex = 0;
73
Michael Jurka7ef959b2011-02-23 11:48:32 -080074 static int getIconContentSize() {
75 return sIconContentSize;
76 }
77
Joe Onorato6665c0f2009-09-02 15:27:24 -070078 /**
Michael Jurka931dc972011-08-05 15:08:15 -070079 * Returns a bitmap suitable for the all apps view. Used to convert pre-ICS
80 * icon bitmaps that are stored in the database (which were 74x74 pixels at hdpi size)
81 * to the proper size (48dp)
82 */
83 static Bitmap createIconBitmap(Bitmap icon, Context context) {
84 int textureWidth = sIconTextureWidth;
85 int textureHeight = sIconTextureHeight;
86 int sourceWidth = icon.getWidth();
87 int sourceHeight = icon.getHeight();
88 if (sourceWidth > textureWidth && sourceHeight > textureHeight) {
89 // Icon is bigger than it should be; clip it (solves the GB->ICS migration case)
90 return Bitmap.createBitmap(icon,
91 (sourceWidth - textureWidth) / 2,
92 (sourceHeight - textureHeight) / 2,
93 textureWidth, textureHeight);
94 } else if (sourceWidth == textureWidth && sourceHeight == textureHeight) {
95 // Icon is the right size, no need to change it
96 return icon;
97 } else {
98 // Icon is too small, render to a larger bitmap
99 return createIconBitmap(new BitmapDrawable(icon), context);
100 }
101 }
102
103 /**
104 * Returns a bitmap suitable for the all apps view.
Joe Onorato6665c0f2009-09-02 15:27:24 -0700105 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800106 static Bitmap createIconBitmap(Drawable icon, Context context) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700107 synchronized (sCanvas) { // we share the statics :-(
108 if (sIconWidth == -1) {
109 initStatics(context);
110 }
111
112 int width = sIconWidth;
113 int height = sIconHeight;
114
Joe Onorato6665c0f2009-09-02 15:27:24 -0700115 if (icon instanceof PaintDrawable) {
116 PaintDrawable painter = (PaintDrawable) icon;
117 painter.setIntrinsicWidth(width);
118 painter.setIntrinsicHeight(height);
119 } else if (icon instanceof BitmapDrawable) {
120 // Ensure the bitmap has a density.
121 BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
122 Bitmap bitmap = bitmapDrawable.getBitmap();
123 if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
124 bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
125 }
126 }
127 int sourceWidth = icon.getIntrinsicWidth();
128 int sourceHeight = icon.getIntrinsicHeight();
129
Michael Jurka931dc972011-08-05 15:08:15 -0700130 if (sourceWidth > 0 && sourceHeight > 0) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700131 // There are intrinsic sizes.
Romain Guy89911d22009-09-28 18:48:49 -0700132 if (width < sourceWidth || height < sourceHeight) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700133 // It's too big, scale it down.
134 final float ratio = (float) sourceWidth / sourceHeight;
135 if (sourceWidth > sourceHeight) {
136 height = (int) (width / ratio);
137 } else if (sourceHeight > sourceWidth) {
138 width = (int) (height * ratio);
139 }
140 } else if (sourceWidth < width && sourceHeight < height) {
Winson Chung4b825dcd2011-06-19 12:41:22 -0700141 // Don't scale up the icon
Joe Onorato6665c0f2009-09-02 15:27:24 -0700142 width = sourceWidth;
Romain Guy89911d22009-09-28 18:48:49 -0700143 height = sourceHeight;
Joe Onorato6665c0f2009-09-02 15:27:24 -0700144 }
145 }
146
147 // no intrinsic size --> use default size
148 int textureWidth = sIconTextureWidth;
149 int textureHeight = sIconTextureHeight;
150
151 final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
152 Bitmap.Config.ARGB_8888);
153 final Canvas canvas = sCanvas;
154 canvas.setBitmap(bitmap);
155
156 final int left = (textureWidth-width) / 2;
157 final int top = (textureHeight-height) / 2;
158
159 if (false) {
160 // draw a big box for the icon for debugging
161 canvas.drawColor(sColors[sColorIndex]);
162 if (++sColorIndex >= sColors.length) sColorIndex = 0;
163 Paint debugPaint = new Paint();
164 debugPaint.setColor(0xffcccc00);
165 canvas.drawRect(left, top, left+width, top+height, debugPaint);
166 }
167
168 sOldBounds.set(icon.getBounds());
169 icon.setBounds(left, top, left+width, top+height);
170 icon.draw(canvas);
171 icon.setBounds(sOldBounds);
Adam Cohenaaf473c2011-08-03 12:02:47 -0700172 canvas.setBitmap(null);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700173
174 return bitmap;
175 }
176 }
177
Joe Onoratoc61cff92009-11-08 11:54:39 -0500178 static void drawSelectedAllAppsBitmap(Canvas dest, int destWidth, int destHeight,
Joe Onoratoeb8325a2009-11-08 13:20:30 -0500179 boolean pressed, Bitmap src) {
Joe Onorato1291a8c2009-09-15 15:07:25 -0400180 synchronized (sCanvas) { // we share the statics :-(
181 if (sIconWidth == -1) {
182 // We can't have gotten to here without src being initialized, which
183 // comes from this file already. So just assert.
184 //initStatics(context);
185 throw new RuntimeException("Assertion failed: Utilities not initialized");
186 }
187
188 dest.drawColor(0, PorterDuff.Mode.CLEAR);
Jason Samsb4ecab22010-01-19 16:43:26 -0800189
Joe Onorato1291a8c2009-09-15 15:07:25 -0400190 int[] xy = new int[2];
Mike Reedcdd11792009-10-29 17:27:55 -0400191 Bitmap mask = src.extractAlpha(sBlurPaint, xy);
Joe Onorato1291a8c2009-09-15 15:07:25 -0400192
Mike Reedcdd11792009-10-29 17:27:55 -0400193 float px = (destWidth - src.getWidth()) / 2;
194 float py = (destHeight - src.getHeight()) / 2;
Joe Onoratoc61cff92009-11-08 11:54:39 -0500195 dest.drawBitmap(mask, px + xy[0], py + xy[1],
Joe Onoratoeb8325a2009-11-08 13:20:30 -0500196 pressed ? sGlowColorPressedPaint : sGlowColorFocusedPaint);
Joe Onorato1291a8c2009-09-15 15:07:25 -0400197
198 mask.recycle();
199 }
200 }
Joe Onorato6665c0f2009-09-02 15:27:24 -0700201
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 /**
203 * Returns a Bitmap representing the thumbnail of the specified Bitmap.
204 * The size of the thumbnail is defined by the dimension
205 * android.R.dimen.launcher_application_icon_size.
206 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 * @param bitmap The bitmap to get a thumbnail of.
208 * @param context The application's context.
209 *
210 * @return A thumbnail for the specified bitmap or the bitmap itself if the
211 * thumbnail could not be created.
212 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800213 static Bitmap resampleIconBitmap(Bitmap bitmap, Context context) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400214 synchronized (sCanvas) { // we share the statics :-(
215 if (sIconWidth == -1) {
Joe Onorato6665c0f2009-09-02 15:27:24 -0700216 initStatics(context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217 }
218
Joe Onorato0589f0f2010-02-08 13:44:00 -0800219 if (bitmap.getWidth() == sIconWidth && bitmap.getHeight() == sIconHeight) {
220 return bitmap;
221 } else {
222 return createIconBitmap(new BitmapDrawable(bitmap), context);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400223 }
Joe Onorato9c1289c2009-08-17 11:03:03 -0400224 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225 }
Joe Onoratobf15cb42009-08-07 14:33:40 -0700226
Joe Onorato56d82912010-03-07 14:32:10 -0500227 static Bitmap drawDisabledBitmap(Bitmap bitmap, Context context) {
228 synchronized (sCanvas) { // we share the statics :-(
229 if (sIconWidth == -1) {
230 initStatics(context);
231 }
232 final Bitmap disabled = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),
233 Bitmap.Config.ARGB_8888);
234 final Canvas canvas = sCanvas;
235 canvas.setBitmap(disabled);
236
237 canvas.drawBitmap(bitmap, 0.0f, 0.0f, sDisabledPaint);
238
Adam Cohenaaf473c2011-08-03 12:02:47 -0700239 canvas.setBitmap(null);
240
Joe Onorato56d82912010-03-07 14:32:10 -0500241 return disabled;
242 }
243 }
244
Joe Onorato6665c0f2009-09-02 15:27:24 -0700245 private static void initStatics(Context context) {
246 final Resources resources = context.getResources();
Joe Onorato1291a8c2009-09-15 15:07:25 -0400247 final DisplayMetrics metrics = resources.getDisplayMetrics();
248 final float density = metrics.density;
249
Michael Jurkac9a96192010-11-01 11:52:08 -0700250 sIconWidth = sIconHeight = (int) resources.getDimension(R.dimen.app_icon_size);
Michael Jurkaa2eb1702011-05-12 14:57:05 -0700251 if (LauncherApplication.isScreenLarge()) {
Michael Jurka7ef959b2011-02-23 11:48:32 -0800252 sIconContentSize = (int) resources.getDimension(R.dimen.app_icon_content_size);
253 }
Winson Chung4b825dcd2011-06-19 12:41:22 -0700254 sIconTextureWidth = sIconTextureHeight = sIconWidth;
Joe Onorato1291a8c2009-09-15 15:07:25 -0400255
Joe Onoratoa4c0cb92009-11-02 10:42:02 -0500256 sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
Joe Onoratoeb8325a2009-11-08 13:20:30 -0500257 sGlowColorPressedPaint.setColor(0xffffc300);
258 sGlowColorPressedPaint.setMaskFilter(TableMaskFilter.CreateClipTable(0, 30));
Joe Onoratoc61cff92009-11-08 11:54:39 -0500259 sGlowColorFocusedPaint.setColor(0xffff8e00);
260 sGlowColorFocusedPaint.setMaskFilter(TableMaskFilter.CreateClipTable(0, 30));
Joe Onorato56d82912010-03-07 14:32:10 -0500261
262 ColorMatrix cm = new ColorMatrix();
263 cm.setSaturation(0.2f);
264 sDisabledPaint.setColorFilter(new ColorMatrixColorFilter(cm));
265 sDisabledPaint.setAlpha(0x88);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700266 }
267
Joe Onoratobf15cb42009-08-07 14:33:40 -0700268 static class BubbleText {
269 private static final int MAX_LINES = 2;
Joe Onoratobf15cb42009-08-07 14:33:40 -0700270
Romain Guy88f38d12010-01-26 14:50:34 -0800271 private final TextPaint mTextPaint;
Joe Onoratobf15cb42009-08-07 14:33:40 -0700272
Romain Guy88f38d12010-01-26 14:50:34 -0800273 private final RectF mBubbleRect = new RectF();
Joe Onoratobf15cb42009-08-07 14:33:40 -0700274
Romain Guy88f38d12010-01-26 14:50:34 -0800275 private final float mTextWidth;
276 private final int mLeading;
277 private final int mFirstLineY;
278 private final int mLineHeight;
279
280 private final int mBitmapWidth;
281 private final int mBitmapHeight;
282 private final int mDensity;
Joe Onoratobf15cb42009-08-07 14:33:40 -0700283
284 BubbleText(Context context) {
285 final Resources resources = context.getResources();
286
Romain Guy88f38d12010-01-26 14:50:34 -0800287 final DisplayMetrics metrics = resources.getDisplayMetrics();
288 final float scale = metrics.density;
289 mDensity = metrics.densityDpi;
Joe Onoratobf15cb42009-08-07 14:33:40 -0700290
Kenny Root97051642010-03-05 13:24:08 -0800291 final float paddingLeft = 2.0f * scale;
292 final float paddingRight = 2.0f * scale;
Romain Guy442eda22010-02-04 15:59:37 -0800293 final float cellWidth = resources.getDimension(R.dimen.title_texture_width);
Joe Onoratobf15cb42009-08-07 14:33:40 -0700294
295 RectF bubbleRect = mBubbleRect;
296 bubbleRect.left = 0;
297 bubbleRect.top = 0;
Romain Guyc0c4fe32010-02-12 23:20:25 +0100298 bubbleRect.right = (int) cellWidth;
Joe Onoratobf15cb42009-08-07 14:33:40 -0700299
Kenny Root97051642010-03-05 13:24:08 -0800300 mTextWidth = cellWidth - paddingLeft - paddingRight;
Joe Onoratobf15cb42009-08-07 14:33:40 -0700301
Joe Onoratobf15cb42009-08-07 14:33:40 -0700302 TextPaint textPaint = mTextPaint = new TextPaint();
Joe Onoratoefabe002009-08-28 09:38:18 -0700303 textPaint.setTypeface(Typeface.DEFAULT);
304 textPaint.setTextSize(13*scale);
Joe Onoratobf15cb42009-08-07 14:33:40 -0700305 textPaint.setColor(0xffffffff);
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700306 textPaint.setAntiAlias(true);
Joe Onorato9392a752009-09-15 17:13:09 -0400307 if (TEXT_BURN) {
308 textPaint.setShadowLayer(8, 0, 0, 0xff000000);
309 }
Joe Onoratobf15cb42009-08-07 14:33:40 -0700310
311 float ascent = -textPaint.ascent();
312 float descent = textPaint.descent();
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700313 float leading = 0.0f;//(ascent+descent) * 0.1f;
Joe Onoratobf15cb42009-08-07 14:33:40 -0700314 mLeading = (int)(leading + 0.5f);
315 mFirstLineY = (int)(leading + ascent + 0.5f);
316 mLineHeight = (int)(leading + ascent + descent + 0.5f);
317
Romain Guy442eda22010-02-04 15:59:37 -0800318 mBitmapWidth = (int)(mBubbleRect.width() + 0.5f);
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700319 mBitmapHeight = roundToPow2((int)((MAX_LINES * mLineHeight) + leading + 0.5f));
Joe Onoratobf15cb42009-08-07 14:33:40 -0700320
Joe Onoratofccc8df2009-10-01 14:30:16 -0700321 mBubbleRect.offsetTo((mBitmapWidth-mBubbleRect.width())/2, 0);
322
Joe Onorato080d9b62009-11-02 12:01:11 -0500323 if (false) {
324 Log.d(TAG, "mBitmapWidth=" + mBitmapWidth + " mBitmapHeight="
325 + mBitmapHeight + " w=" + ((int)(mBubbleRect.width() + 0.5f))
326 + " h=" + ((int)((MAX_LINES * mLineHeight) + leading + 0.5f)));
327 }
Joe Onoratobf15cb42009-08-07 14:33:40 -0700328 }
329
330 /** You own the bitmap after this and you must call recycle on it. */
331 Bitmap createTextBitmap(String text) {
Jason Sams6ec11bc2010-01-19 17:56:52 -0800332 Bitmap b = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight, Bitmap.Config.ALPHA_8);
Romain Guy88f38d12010-01-26 14:50:34 -0800333 b.setDensity(mDensity);
Joe Onoratobf15cb42009-08-07 14:33:40 -0700334 Canvas c = new Canvas(b);
335
336 StaticLayout layout = new StaticLayout(text, mTextPaint, (int)mTextWidth,
337 Alignment.ALIGN_CENTER, 1, 0, true);
338 int lineCount = layout.getLineCount();
339 if (lineCount > MAX_LINES) {
340 lineCount = MAX_LINES;
341 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700342 //if (!TEXT_BURN && lineCount > 0) {
343 //RectF bubbleRect = mBubbleRect;
344 //bubbleRect.bottom = height(lineCount);
345 //c.drawRoundRect(bubbleRect, mCornerRadius, mCornerRadius, mRectPaint);
346 //}
Joe Onoratobf15cb42009-08-07 14:33:40 -0700347 for (int i=0; i<lineCount; i++) {
Joe Onoratofccc8df2009-10-01 14:30:16 -0700348 //int x = (int)((mBubbleRect.width() - layout.getLineMax(i)) / 2.0f);
349 //int y = mFirstLineY + (i * mLineHeight);
Romain Guy88f38d12010-01-26 14:50:34 -0800350 final String lineText = text.substring(layout.getLineStart(i), layout.getLineEnd(i));
Joe Onoratofccc8df2009-10-01 14:30:16 -0700351 int x = (int)(mBubbleRect.left
Romain Guy88f38d12010-01-26 14:50:34 -0800352 + ((mBubbleRect.width() - mTextPaint.measureText(lineText)) * 0.5f));
Joe Onoratobf15cb42009-08-07 14:33:40 -0700353 int y = mFirstLineY + (i * mLineHeight);
Romain Guy88f38d12010-01-26 14:50:34 -0800354 c.drawText(lineText, x, y, mTextPaint);
Joe Onoratobf15cb42009-08-07 14:33:40 -0700355 }
356
Adam Cohenaaf473c2011-08-03 12:02:47 -0700357 c.setBitmap(null);
Joe Onoratobf15cb42009-08-07 14:33:40 -0700358 return b;
359 }
Joe Onorato43e7bcf2009-08-08 18:53:53 -0700360
361 private int height(int lineCount) {
362 return (int)((lineCount * mLineHeight) + mLeading + mLeading + 0.0f);
363 }
364
365 int getBubbleWidth() {
366 return (int)(mBubbleRect.width() + 0.5f);
367 }
368
369 int getMaxBubbleHeight() {
370 return height(MAX_LINES);
371 }
372
373 int getBitmapWidth() {
374 return mBitmapWidth;
375 }
376
377 int getBitmapHeight() {
378 return mBitmapHeight;
379 }
Joe Onoratobf15cb42009-08-07 14:33:40 -0700380 }
381
382 /** Only works for positive numbers. */
383 static int roundToPow2(int n) {
384 int orig = n;
385 n >>= 1;
386 int mask = 0x8000000;
387 while (mask != 0 && (n & mask) == 0) {
388 mask >>= 1;
389 }
390 while (mask != 0) {
391 n |= mask;
392 mask >>= 1;
393 }
394 n += 1;
395 if (n != orig) {
396 n <<= 1;
397 }
398 return n;
399 }
Winson Chung97d85d22011-04-13 11:27:36 -0700400
401 static int generateRandomId() {
402 return new Random(System.currentTimeMillis()).nextInt(1 << 24);
403 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404}