am 792f38dd: Merge "Fix the delegate method signatures in LayoutLib"

* commit '792f38ddd9e8d25b2c8bf0d67363dbfa56550636':
  Fix the delegate method signatures in LayoutLib
This commit is contained in:
Deepanshu Gupta
2014-03-11 16:16:18 -07:00
committed by Android Git Automerger
6 changed files with 46 additions and 94 deletions

View File

@@ -44,62 +44,13 @@ import java.util.Set;
*/
/*package*/ class BitmapFactory_Delegate {
// ------ Java delegates ------
@LayoutlibDelegate
/*package*/ static Bitmap finishDecode(Bitmap bm, Rect outPadding, Options opts) {
if (bm == null || opts == null) {
return bm;
}
final int density = opts.inDensity;
if (density == 0) {
return bm;
}
bm.setDensity(density);
final int targetDensity = opts.inTargetDensity;
if (targetDensity == 0 || density == targetDensity || density == opts.inScreenDensity) {
return bm;
}
byte[] np = bm.getNinePatchChunk();
final boolean isNinePatch = np != null && NinePatch.isNinePatchChunk(np);
// DELEGATE CHANGE: never scale 9-patch
if (opts.inScaled && isNinePatch == false) {
float scale = targetDensity / (float)density;
// TODO: This is very inefficient and should be done in native by Skia
final Bitmap oldBitmap = bm;
bm = Bitmap.createScaledBitmap(oldBitmap, (int) (bm.getWidth() * scale + 0.5f),
(int) (bm.getHeight() * scale + 0.5f), true);
oldBitmap.recycle();
if (isNinePatch) {
np = nativeScaleNinePatch(np, scale, outPadding);
bm.setNinePatchChunk(np);
}
bm.setDensity(targetDensity);
}
return bm;
}
// ------ Native Delegates ------
@LayoutlibDelegate
/*package*/ static Bitmap nativeDecodeStream(InputStream is, byte[] storage,
Rect padding, Options opts) {
return nativeDecodeStream(is, storage, padding, opts, false, 1.f);
}
@LayoutlibDelegate
/*package*/ static Bitmap nativeDecodeStream(InputStream is, byte[] storage,
Rect padding, Options opts, boolean applyScale, float scale) {
Bitmap bm = null;
//TODO support rescaling
Density density = Density.MEDIUM;
Set<BitmapCreateFlags> bitmapCreateFlags = EnumSet.of(BitmapCreateFlags.MUTABLE);
if (opts != null) {
@@ -156,13 +107,6 @@ import java.util.Set;
return null;
}
@LayoutlibDelegate
/*package*/ static Bitmap nativeDecodeAsset(long asset, Rect padding, Options opts,
boolean applyScale, float scale) {
opts.inBitmap = null;
return null;
}
@LayoutlibDelegate
/*package*/ static Bitmap nativeDecodeByteArray(byte[] data, int offset,
int length, Options opts) {
@@ -170,13 +114,6 @@ import java.util.Set;
return null;
}
@LayoutlibDelegate
/*package*/ static byte[] nativeScaleNinePatch(byte[] chunk, float scale, Rect pad) {
// don't scale for now. This should not be called anyway since we re-implement
// BitmapFactory.finishDecode();
return chunk;
}
@LayoutlibDelegate
/*package*/ static boolean nativeIsSeekable(FileDescriptor fd) {
return true;

View File

@@ -313,6 +313,13 @@ public final class Bitmap_Delegate {
return true;
}
@LayoutlibDelegate
/*package*/ static void nativeReconfigure(long nativeBitmap, int width, int height,
int config, int allocSize) {
Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
"Bitmap.reconfigure() is not supported", null /*data*/);
}
@LayoutlibDelegate
/*package*/ static boolean nativeCompress(long nativeBitmap, int format, int quality,
OutputStream stream, byte[] tempStorage) {
@@ -341,28 +348,6 @@ public final class Bitmap_Delegate {
}
}
@LayoutlibDelegate
/*package*/ static int nativeWidth(long nativeBitmap) {
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return 0;
}
return delegate.mImage.getWidth();
}
@LayoutlibDelegate
/*package*/ static int nativeHeight(long nativeBitmap) {
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return 0;
}
return delegate.mImage.getHeight();
}
@LayoutlibDelegate
/*package*/ static int nativeRowBytes(long nativeBitmap) {
// get the delegate from the native int.
@@ -408,19 +393,21 @@ public final class Bitmap_Delegate {
}
@LayoutlibDelegate
/*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y) {
/*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y,
boolean isPremultiplied) {
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return 0;
}
// TODO: Support isPremultiplied.
return delegate.mImage.getRGB(x, y);
}
@LayoutlibDelegate
/*package*/ static void nativeGetPixels(long nativeBitmap, int[] pixels, int offset,
int stride, int x, int y, int width, int height) {
int stride, int x, int y, int width, int height, boolean isPremultiplied) {
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
@@ -431,7 +418,8 @@ public final class Bitmap_Delegate {
@LayoutlibDelegate
/*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color) {
/*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color,
boolean isPremultiplied) {
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
@@ -442,7 +430,7 @@ public final class Bitmap_Delegate {
@LayoutlibDelegate
/*package*/ static void nativeSetPixels(long nativeBitmap, int[] colors, int offset,
int stride, int x, int y, int width, int height) {
int stride, int x, int y, int width, int height, boolean isPremultiplied) {
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;

View File

@@ -167,6 +167,7 @@ public final class NinePatch_Delegate {
return sManager.addNewDelegate(newDelegate);
}
@LayoutlibDelegate
/*package*/ static void nativeFinalize(long chunk) {
sManager.removeJavaReferenceFor(chunk);
}

View File

@@ -401,17 +401,17 @@ public final class Path_Delegate {
}
@LayoutlibDelegate
/*package*/ static void native_addPath(long nPath, int src, float dx, float dy) {
/*package*/ static void native_addPath(long nPath, long src, float dx, float dy) {
addPath(nPath, src, AffineTransform.getTranslateInstance(dx, dy));
}
@LayoutlibDelegate
/*package*/ static void native_addPath(long nPath, int src) {
/*package*/ static void native_addPath(long nPath, long src) {
addPath(nPath, src, null /*transform*/);
}
@LayoutlibDelegate
/*package*/ static void native_addPath(long nPath, int src, long matrix) {
/*package*/ static void native_addPath(long nPath, long src, long matrix) {
Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(matrix);
if (matrixDelegate == null) {
return;
@@ -473,6 +473,12 @@ public final class Path_Delegate {
native_transform(nPath, matrix, 0);
}
@LayoutlibDelegate
/*package*/ static boolean native_op(long nPath1, long nPath2, int op, long result) {
Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED, "Path.op() not supported", null);
return false;
}
@LayoutlibDelegate
/*package*/ static void finalizer(long nPath) {
sManager.removeJavaReferenceFor(nPath);

View File

@@ -21,6 +21,7 @@ import java.text.FieldPosition;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import com.ibm.icu.text.DateIntervalFormat;
import com.ibm.icu.util.DateInterval;
import com.ibm.icu.util.TimeZone;
@@ -38,6 +39,7 @@ public class DateIntervalFormat_Delegate {
// ---- native methods ----
@LayoutlibDelegate
/*package*/static String formatDateInterval(long address, long fromDate, long toDate) {
DateIntervalFormat_Delegate delegate = sManager.getDelegate((int)address);
if (delegate == null) {
@@ -52,6 +54,7 @@ public class DateIntervalFormat_Delegate {
return sb.toString();
}
@LayoutlibDelegate
/*package*/ static long createDateIntervalFormat(String skeleton, String localeName,
String tzName) {
TimeZone prevDefaultTz = TimeZone.getDefault();
@@ -63,6 +66,7 @@ public class DateIntervalFormat_Delegate {
return sManager.addNewDelegate(newDelegate);
}
@LayoutlibDelegate
/*package*/ static void destroyDateIntervalFormat(long address) {
sManager.removeJavaReferenceFor((int)address);
}

View File

@@ -46,7 +46,7 @@ public class ICU_Delegate {
// --- Native methods accessing ICU's database.
@LayoutlibDelegate
/*package*/ static String getBestDateTimePattern(String skeleton, String localeName) {
/*package*/ static String getBestDateTimePatternNative(String skeleton, String localeName) {
return DateTimePatternGenerator.getInstance(new ULocale(localeName))
.getBestPattern(skeleton);
}
@@ -136,6 +136,11 @@ public class ICU_Delegate {
return "";
}
@LayoutlibDelegate
/*package*/ static String getDisplayScriptNative(String variantCode, String locale) {
return "";
}
@LayoutlibDelegate
/*package*/ static String getISO3CountryNative(String locale) {
return "";
@@ -166,8 +171,19 @@ public class ICU_Delegate {
return Locale.getISOCountries();
}
@LayoutlibDelegate
/*package*/ static boolean initLocaleDataImpl(String locale, LocaleData result) {
/*package*/ static String localeForLanguageTag(String languageTag, boolean strict) {
return "";
}
@LayoutlibDelegate
/*package*/ static String languageTagForLocale(String locale) {
return "";
}
@LayoutlibDelegate
/*package*/ static boolean initLocaleDataNative(String locale, LocaleData result) {
// Used by Calendar.
result.firstDayOfWeek = Integer.valueOf(1);