android: optimize code style
This commit is contained in:
parent
8c57e5e500
commit
829063e0ff
@ -70,7 +70,7 @@ public class DoricContext {
|
|||||||
private final DoricPerformanceProfile performanceProfile;
|
private final DoricPerformanceProfile performanceProfile;
|
||||||
private final Map<String, Animator> animators = new HashMap<>();
|
private final Map<String, Animator> animators = new HashMap<>();
|
||||||
private final Map<String, DoricResource> cachedResources = new WeakHashMap<>();
|
private final Map<String, DoricResource> cachedResources = new WeakHashMap<>();
|
||||||
private final ArrayList<SoftReference<RetainedJavaValue>> retainedJavaValues = new ArrayList<>();
|
private final Set<SoftReference<RetainedJavaValue>> retainedJavaValues = new HashSet<>();
|
||||||
|
|
||||||
public Collection<ViewNode<?>> allHeadNodes(String type) {
|
public Collection<ViewNode<?>> allHeadNodes(String type) {
|
||||||
Map<String, ViewNode<?>> headNode = mHeadNodes.get(type);
|
Map<String, ViewNode<?>> headNode = mHeadNodes.get(type);
|
||||||
@ -225,7 +225,6 @@ public class DoricContext {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, ThreadMode.UI);
|
}, ThreadMode.UI);
|
||||||
|
|
||||||
retainedJavaValues.clear();
|
retainedJavaValues.clear();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6,18 +6,18 @@ import java.lang.ref.SoftReference;
|
|||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
public class RetainedJavaValue extends JavaValue {
|
public class RetainedJavaValue extends JavaValue {
|
||||||
private final WeakReference<DoricContext> mDoricContext;
|
private final WeakReference<DoricContext> contextRef;
|
||||||
|
|
||||||
public RetainedJavaValue(WeakReference<DoricContext> doricContext, byte[] data) {
|
public RetainedJavaValue(DoricContext doricContext, byte[] data) {
|
||||||
super(data);
|
super(data);
|
||||||
|
contextRef = new WeakReference<>(doricContext);
|
||||||
this.mDoricContext = doricContext;
|
final SoftReference<RetainedJavaValue> softRef = new SoftReference<>(this);
|
||||||
this.mDoricContext.get().retainJavaValue(new SoftReference<>(this));
|
doricContext.retainJavaValue(softRef);
|
||||||
this.memoryReleaser = new MemoryReleaser() {
|
this.memoryReleaser = new MemoryReleaser() {
|
||||||
@Override
|
@Override
|
||||||
public void deallocate(byte[] data) {
|
public void deallocate(byte[] data) {
|
||||||
if (doricContext.get() != null) {
|
if (contextRef.get() != null) {
|
||||||
doricContext.get().releaseJavaValue(new SoftReference<>(RetainedJavaValue.this));
|
contextRef.get().releaseJavaValue(softRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,6 @@ import com.github.pengfeizhou.jscore.JSONBuilder;
|
|||||||
import com.github.pengfeizhou.jscore.JSObject;
|
import com.github.pengfeizhou.jscore.JSObject;
|
||||||
import com.github.pengfeizhou.jscore.JavaValue;
|
import com.github.pengfeizhou.jscore.JavaValue;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
@ -97,8 +96,7 @@ public class ImageDecoderPlugin extends DoricJavaPlugin {
|
|||||||
Bitmap bitmap = BitmapFactory.decodeByteArray(rawData, 0, rawData.length);
|
Bitmap bitmap = BitmapFactory.decodeByteArray(rawData, 0, rawData.length);
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
|
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
|
||||||
bitmap.copyPixelsToBuffer(buffer);
|
bitmap.copyPixelsToBuffer(buffer);
|
||||||
|
RetainedJavaValue retainedJavaValue = new RetainedJavaValue(getDoricContext(), buffer.array());
|
||||||
RetainedJavaValue retainedJavaValue = new RetainedJavaValue(new WeakReference<DoricContext>(getDoricContext()), buffer.array());
|
|
||||||
promise.resolve(retainedJavaValue);
|
promise.resolve(retainedJavaValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user