static Bitmap[] smartNotify(Context context, Bitmap icon, String header, String body) { Properties props = BitmapCache.getProperties(context, "notification_sticky.xml"); final int textTop = Integer.parseInt(props.getProperty("textTop", "24")); final int textLeft = Integer.parseInt(props.getProperty("textLeft", "3")); final int textWidth = Integer.parseInt(props.getProperty("textWidth", "85")); final int textHeight = Integer.parseInt(props.getProperty("textHeight", "69")); final int iconTop = Integer.parseInt(props.getProperty("iconTop", "0")); final int iconLeft = Integer.parseInt(props.getProperty("iconLeft", "0")); final int headerLeft = Integer.parseInt(props.getProperty("headerLeft", "20")); final int headerBaseline = Integer.parseInt(props.getProperty("headerBaseline", "15")); final int headerColor = props.getProperty("headerColor", "white").equalsIgnoreCase("black") ? Color.BLACK : Color.WHITE; final int textColor = props.getProperty("textColor", "black").equalsIgnoreCase("black") ? Color.BLACK : Color.WHITE; final int arrowUpLeft = Integer.parseInt(props.getProperty("arrowUpLeft", "91")); final int arrowUpTop = Integer.parseInt(props.getProperty("arrowUpTop", "23")); final int arrowDownLeft = Integer.parseInt(props.getProperty("arrowDownLeft", "91")); final int arrowDownTop = Integer.parseInt(props.getProperty("arrowDownTop", "56")); final int closeLeft = Integer.parseInt(props.getProperty("closeLeft", "91")); final int closeTop = Integer.parseInt(props.getProperty("closeTop", "89")); FontInfo font = FontCache.instance(context).Get(); List<Bitmap> bitmaps = new ArrayList<Bitmap>(); Paint paintHead = new Paint(); paintHead.setColor(headerColor); paintHead.setTextSize(FontCache.instance(context).Large.size); paintHead.setTypeface(FontCache.instance(context).Large.face); Paint paint = new Paint(); paint.setColor(textColor); paint.setTextSize(font.size); paint.setTypeface(font.face); Paint whitePaint = new Paint(); whitePaint.setColor(Color.WHITE); TextPaint textPaint = new TextPaint(paint); StaticLayout staticLayout = new StaticLayout( body, textPaint, textWidth, android.text.Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false); int iconHeight = 16; int iconOffset = 0; if (icon != null) { iconHeight = Math.max(16, icon.getHeight()); iconOffset = iconHeight - icon.getHeight(); // align icon to bottom of text } int h = staticLayout.getHeight(); int y = 0; int displayHeight = textHeight + 3; int scroll = textHeight - font.size; boolean more = true; int pages = 0; while (more) { more = false; Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); canvas.drawBitmap(Utils.getBitmap(context, "notify_background_sticky.png"), 0, 0, null); canvas.save(); canvas.translate(textLeft, textTop - y); // position the text canvas.clipRect(0, y, textWidth, textHeight + y); staticLayout.draw(canvas); canvas.restore(); // Draw header if (icon != null) canvas.drawBitmap(icon, iconLeft, iconOffset + iconTop, paint); canvas.drawText(header, headerLeft, headerBaseline, paintHead); if (y > 0) canvas.drawBitmap(Utils.getBitmap(context, "arrow_up.bmp"), arrowUpLeft, arrowUpTop, null); if ((h - y) > (displayHeight) && pages < 10) { more = true; pages++; canvas.drawBitmap( Utils.getBitmap(context, "arrow_down.bmp"), arrowDownLeft, arrowDownTop, null); } canvas.drawBitmap(Utils.getBitmap(context, "close.bmp"), closeLeft, closeTop, null); y += scroll; bitmaps.add(bitmap); } Bitmap[] bitmapArray = new Bitmap[bitmaps.size()]; bitmaps.toArray(bitmapArray); return bitmapArray; }
static Bitmap smartLines( Context context, Bitmap icon, String header, String[] lines, FontCache.FontSize size) { Properties props = BitmapCache.getProperties(context, "notification.xml"); final int textTop = Integer.parseInt(props.getProperty("textTop", "24")); final int textLeft = Integer.parseInt(props.getProperty("textLeft", "3")); final int textWidth = Integer.parseInt(props.getProperty("textWidth", "90")); final int textHeight = Integer.parseInt(props.getProperty("textHeight", "69")); final int iconTop = Integer.parseInt(props.getProperty("iconTop", "0")); final int iconLeft = Integer.parseInt(props.getProperty("iconLeft", "0")); final int headerLeft = Integer.parseInt(props.getProperty("headerLeft", "20")); final int headerBaseline = Integer.parseInt(props.getProperty("headerBaseline", "15")); final int headerColor = props.getProperty("headerColor", "white").equalsIgnoreCase("black") ? Color.BLACK : Color.WHITE; final int textColor = props.getProperty("textColor", "black").equalsIgnoreCase("black") ? Color.BLACK : Color.WHITE; FontInfo font = FontCache.instance(context).Get(size); Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); Paint paintHead = new Paint(); paintHead.setColor(headerColor); paintHead.setTextSize(FontCache.instance(context).Large.size); paintHead.setTypeface(FontCache.instance(context).Large.face); Paint paint = new Paint(); paint.setColor(textColor); paint.setTextSize(font.size); paint.setTypeface(font.face); canvas.drawColor(Color.WHITE); canvas.drawBitmap(Utils.getBitmap(context, "notify_background.png"), 0, 0, null); int iconHeight = 16; if (icon != null) { iconHeight = Math.max(16, icon.getHeight()); // make sure the text fits // align icon to bottom of text canvas.drawBitmap(icon, iconLeft, iconTop + iconHeight - icon.getHeight(), paint); } canvas.drawText(header, headerLeft, headerBaseline, paintHead); String body = ""; for (String line : lines) { if (body.length() > 0) body += "\n\n"; body += line; } TextPaint textPaint = new TextPaint(paint); StaticLayout staticLayout = new StaticLayout( body, textPaint, textWidth, android.text.Layout.Alignment.ALIGN_CENTER, 1.3f, 0, false); int layoutHeight = staticLayout.getHeight(); int textY = textTop + (textHeight / 2) - (layoutHeight / 2); if (textY < textTop) textY = textTop; canvas.translate(textLeft, textY); // position the text staticLayout.draw(canvas); return bitmap; }