@LayoutlibDelegate /*package*/ static long validateNinePatchChunk(byte[] chunk) { // the default JNI implementation only checks that the byte[] has the same // size as the C struct it represent. Since we cannot do the same check (serialization // will return different size depending on content), we do nothing. NinePatch_Delegate newDelegate = new NinePatch_Delegate(); newDelegate.chunk = chunk; return sManager.addNewDelegate(newDelegate); }
@LayoutlibDelegate /*package*/ static long createDateIntervalFormat( String skeleton, String localeName, String tzName) { TimeZone prevDefaultTz = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone(tzName)); DateIntervalFormat_Delegate newDelegate = new DateIntervalFormat_Delegate(); newDelegate.mFormat = DateIntervalFormat.getInstance(skeleton, new ULocale(localeName)); TimeZone.setDefault(prevDefaultTz); return sManager.addNewDelegate(newDelegate); }
@LayoutlibDelegate /*package*/ static String formatDateInterval(long address, long fromDate, long toDate) { DateIntervalFormat_Delegate delegate = sManager.getDelegate((int) address); if (delegate == null) { Bridge.getLog() .error(LayoutLog.TAG_BROKEN, "Unable for find native DateIntervalFormat", null); return null; } DateInterval interval = new DateInterval(fromDate, toDate); StringBuffer sb = new StringBuffer(); FieldPosition pos = new FieldPosition(0); delegate.mFormat.format(interval, sb, pos); return sb.toString(); }
@LayoutlibDelegate /*package*/ static void destroyDateIntervalFormat(long address) { sManager.removeJavaReferenceFor((int) address); }
private static void draw( long canvas_instance, final int left, final int top, final int right, final int bottom, Bitmap bitmap_instance, long chunk, long paint_instance_or_null, final int destDensity, final int srcDensity) { // get the delegate from the native int. final Bitmap_Delegate bitmap_delegate = Bitmap_Delegate.getDelegate(bitmap_instance); if (bitmap_delegate == null) { return; } byte[] c = null; NinePatch_Delegate delegate = sManager.getDelegate(chunk); if (delegate != null) { c = delegate.chunk; } if (c == null) { // not a 9-patch? BufferedImage image = bitmap_delegate.getImage(); Canvas_Delegate.native_drawBitmap( null, canvas_instance, bitmap_instance, 0f, 0f, (float) image.getWidth(), (float) image.getHeight(), (float) left, (float) top, (float) right, (float) bottom, paint_instance_or_null, destDensity, srcDensity); return; } final NinePatchChunk chunkObject = getChunk(c); assert chunkObject != null; if (chunkObject == null) { return; } Canvas_Delegate canvas_delegate = Canvas_Delegate.getDelegate(canvas_instance); if (canvas_delegate == null) { return; } // this one can be null Paint_Delegate paint_delegate = Paint_Delegate.getDelegate(paint_instance_or_null); canvas_delegate .getSnapshot() .draw( new GcSnapshot.Drawable() { @Override public void draw(Graphics2D graphics, Paint_Delegate paint) { chunkObject.draw( bitmap_delegate.getImage(), graphics, left, top, right - left, bottom - top, destDensity, srcDensity); } }, paint_delegate, true /*compositeOnly*/, false /*forceSrcMode*/); }
@LayoutlibDelegate /*package*/ static void nativeFinalize(long chunk) { sManager.removeJavaReferenceFor(chunk); }