Skip to content

Commit

Permalink
code cleaning and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
koral-- committed Oct 8, 2016
1 parent 190baf5 commit 81117e4
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 93 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- custom ndk buildscript replaced with `externalNativeBuild`
- Gradle wrapper updated to 3.1
- Build tools version updated to 24.0.3
- NDK version updated to 13
- native code optimizations

### 1.2.2
- Fixed NPE in `GifTexImage2D` finalizer when constructor threw an exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public GifAnimationMetaData(@NonNull AssetManager assets, @NonNull String assetN
* @throws NullPointerException if filePath is null
*/
public GifAnimationMetaData(@NonNull String filePath) throws IOException {
this(new GifInfoHandle(filePath, true));
this(new GifInfoHandle(filePath));
}

/**
Expand All @@ -93,7 +93,7 @@ public GifAnimationMetaData(@NonNull File file) throws IOException {
* @throws NullPointerException if stream is null
*/
public GifAnimationMetaData(@NonNull InputStream stream) throws IOException {
this(new GifInfoHandle(stream, true));
this(new GifInfoHandle(stream));
}

/**
Expand All @@ -105,7 +105,7 @@ public GifAnimationMetaData(@NonNull InputStream stream) throws IOException {
* @throws IOException when opening failed
*/
public GifAnimationMetaData(@NonNull AssetFileDescriptor afd) throws IOException {
this(new GifInfoHandle(afd, true));
this(new GifInfoHandle(afd));
}

/**
Expand All @@ -116,7 +116,7 @@ public GifAnimationMetaData(@NonNull AssetFileDescriptor afd) throws IOException
* @throws NullPointerException if fd is null
*/
public GifAnimationMetaData(@NonNull FileDescriptor fd) throws IOException {
this(new GifInfoHandle(fd, true));
this(new GifInfoHandle(fd));
}

/**
Expand All @@ -128,7 +128,7 @@ public GifAnimationMetaData(@NonNull FileDescriptor fd) throws IOException {
* @throws NullPointerException if bytes are null
*/
public GifAnimationMetaData(@NonNull byte[] bytes) throws IOException {
this(new GifInfoHandle(bytes, true));
this(new GifInfoHandle(bytes));
}

/**
Expand All @@ -140,7 +140,7 @@ public GifAnimationMetaData(@NonNull byte[] bytes) throws IOException {
* @throws NullPointerException if buffer is null
*/
public GifAnimationMetaData(@NonNull ByteBuffer buffer) throws IOException {
this(new GifInfoHandle(buffer, true));
this(new GifInfoHandle(buffer));
}

/**
Expand All @@ -153,7 +153,7 @@ public GifAnimationMetaData(@NonNull ByteBuffer buffer) throws IOException {
* @throws IOException if resolution fails or destination is not a GIF.
*/
public GifAnimationMetaData(@Nullable ContentResolver resolver, @NonNull Uri uri) throws IOException {
this(GifInfoHandle.openUri(resolver, uri, true));
this(GifInfoHandle.openUri(resolver, uri));
}

private GifAnimationMetaData(final GifInfoHandle gifInfoHandle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public GifDrawable(@NonNull AssetManager assets, @NonNull String assetName) thro
* @throws NullPointerException if filePath is null
*/
public GifDrawable(@NonNull String filePath) throws IOException {
this(new GifInfoHandle(filePath, false), null, null, true);
this(new GifInfoHandle(filePath), null, null, true);
}

/**
Expand All @@ -145,7 +145,7 @@ public GifDrawable(@NonNull File file) throws IOException {
* @throws NullPointerException if stream is null
*/
public GifDrawable(@NonNull InputStream stream) throws IOException {
this(new GifInfoHandle(stream, false), null, null, true);
this(new GifInfoHandle(stream), null, null, true);
}

/**
Expand All @@ -157,7 +157,7 @@ public GifDrawable(@NonNull InputStream stream) throws IOException {
* @throws IOException when opening failed
*/
public GifDrawable(@NonNull AssetFileDescriptor afd) throws IOException {
this(new GifInfoHandle(afd, false), null, null, true);
this(new GifInfoHandle(afd), null, null, true);
}

/**
Expand All @@ -168,7 +168,7 @@ public GifDrawable(@NonNull AssetFileDescriptor afd) throws IOException {
* @throws NullPointerException if fd is null
*/
public GifDrawable(@NonNull FileDescriptor fd) throws IOException {
this(new GifInfoHandle(fd, false), null, null, true);
this(new GifInfoHandle(fd), null, null, true);
}

/**
Expand All @@ -180,7 +180,7 @@ public GifDrawable(@NonNull FileDescriptor fd) throws IOException {
* @throws NullPointerException if bytes are null
*/
public GifDrawable(@NonNull byte[] bytes) throws IOException {
this(new GifInfoHandle(bytes, false), null, null, true);
this(new GifInfoHandle(bytes), null, null, true);
}

/**
Expand All @@ -192,7 +192,7 @@ public GifDrawable(@NonNull byte[] bytes) throws IOException {
* @throws NullPointerException if buffer is null
*/
public GifDrawable(@NonNull ByteBuffer buffer) throws IOException {
this(new GifInfoHandle(buffer, false), null, null, true);
this(new GifInfoHandle(buffer), null, null, true);
}

/**
Expand All @@ -205,7 +205,7 @@ public GifDrawable(@NonNull ByteBuffer buffer) throws IOException {
* @throws IOException if resolution fails or destination is not a GIF.
*/
public GifDrawable(@Nullable ContentResolver resolver, @NonNull Uri uri) throws IOException {
this(GifInfoHandle.openUri(resolver, uri, false), null, null, true);
this(GifInfoHandle.openUri(resolver, uri), null, null, true);
}

GifDrawable(GifInfoHandle gifInfoHandle, final GifDrawable oldDrawable, ScheduledThreadPoolExecutor executor, boolean isRenderingTriggeredOnDraw) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,53 @@ final class GifInfoHandle {
GifInfoHandle() {
}

GifInfoHandle(FileDescriptor fd, boolean justDecodeMetaData) throws GifIOException {
gifInfoPtr = openFd(fd, 0, justDecodeMetaData);
GifInfoHandle(FileDescriptor fd) throws GifIOException {
gifInfoPtr = openFd(fd, 0);
}

GifInfoHandle(byte[] bytes, boolean justDecodeMetaData) throws GifIOException {
gifInfoPtr = openByteArray(bytes, justDecodeMetaData);
GifInfoHandle(byte[] bytes) throws GifIOException {
gifInfoPtr = openByteArray(bytes);
}

GifInfoHandle(ByteBuffer buffer, boolean justDecodeMetaData) throws GifIOException {
gifInfoPtr = openDirectByteBuffer(buffer, justDecodeMetaData);
GifInfoHandle(ByteBuffer buffer) throws GifIOException {
gifInfoPtr = openDirectByteBuffer(buffer);
}

GifInfoHandle(String filePath, boolean justDecodeMetaData) throws GifIOException {
gifInfoPtr = openFile(filePath, justDecodeMetaData);
GifInfoHandle(String filePath) throws GifIOException {
gifInfoPtr = openFile(filePath);
}

GifInfoHandle(InputStream stream, boolean justDecodeMetaData) throws GifIOException {
GifInfoHandle(InputStream stream) throws GifIOException {
if (!stream.markSupported()) {
throw new IllegalArgumentException("InputStream does not support marking");
}
gifInfoPtr = openStream(stream, justDecodeMetaData);
gifInfoPtr = openStream(stream);
}

GifInfoHandle(AssetFileDescriptor afd, boolean justDecodeMetaData) throws IOException {
GifInfoHandle(AssetFileDescriptor afd) throws IOException {
try {
gifInfoPtr = openFd(afd.getFileDescriptor(), afd.getStartOffset(), justDecodeMetaData);
gifInfoPtr = openFd(afd.getFileDescriptor(), afd.getStartOffset());
} finally {
afd.close();
}
}

static GifInfoHandle openUri(ContentResolver resolver, Uri uri, boolean justDecodeMetaData) throws IOException {
static GifInfoHandle openUri(ContentResolver resolver, Uri uri) throws IOException {
if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { //workaround for #128
return new GifInfoHandle(uri.getPath(), justDecodeMetaData);
return new GifInfoHandle(uri.getPath());
}
return new GifInfoHandle(resolver.openAssetFileDescriptor(uri, "r"), justDecodeMetaData);
return new GifInfoHandle(resolver.openAssetFileDescriptor(uri, "r"));
}

static native long openFd(FileDescriptor fd, long offset, boolean justDecodeMetaData) throws GifIOException;
static native long openFd(FileDescriptor fd, long offset) throws GifIOException;

static native long openByteArray(byte[] bytes, boolean justDecodeMetaData) throws GifIOException;
static native long openByteArray(byte[] bytes) throws GifIOException;

static native long openDirectByteBuffer(ByteBuffer buffer, boolean justDecodeMetaData) throws GifIOException;
static native long openDirectByteBuffer(ByteBuffer buffer) throws GifIOException;

static native long openStream(InputStream stream, boolean justDecodeMetaData) throws GifIOException;
static native long openStream(InputStream stream) throws GifIOException;

static native long openFile(String filePath, boolean justDecodeMetaData) throws GifIOException;
static native long openFile(String filePath) throws GifIOException;

private static native long renderFrame(long gifFileInPtr, Bitmap frameBuffer);

Expand Down Expand Up @@ -243,6 +243,7 @@ synchronized boolean isRecycled() {
}

@Override
@SuppressWarnings("ThrowFromFinallyBlock")
protected void finalize() throws Throwable {
try {
recycle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public int getHeight() {
}

@Override
@SuppressWarnings("ThrowFromFinallyBlock")
protected final void finalize() throws Throwable {
try {
recycle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public DirectByteBufferSource(@NonNull ByteBuffer byteBuffer) {

@Override
GifInfoHandle open() throws GifIOException {
return new GifInfoHandle(byteBuffer, false);
return new GifInfoHandle(byteBuffer);
}
}

Expand All @@ -73,7 +73,7 @@ public ByteArraySource(@NonNull byte[] bytes) {

@Override
GifInfoHandle open() throws GifIOException {
return new GifInfoHandle(bytes, false);
return new GifInfoHandle(bytes);
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public FileSource(@NonNull String filePath) {

@Override
GifInfoHandle open() throws GifIOException {
return new GifInfoHandle(mPath, false);
return new GifInfoHandle(mPath);
}
}

Expand All @@ -127,7 +127,7 @@ public UriSource(@Nullable ContentResolver contentResolver, @NonNull Uri uri) {

@Override
GifInfoHandle open() throws IOException {
return GifInfoHandle.openUri(mContentResolver, mUri, false);
return GifInfoHandle.openUri(mContentResolver, mUri);
}
}

Expand All @@ -151,7 +151,7 @@ public AssetSource(@NonNull AssetManager assetManager, @NonNull String assetName

@Override
GifInfoHandle open() throws IOException {
return new GifInfoHandle(mAssetManager.openFd(mAssetName), false);
return new GifInfoHandle(mAssetManager.openFd(mAssetName));
}
}

Expand All @@ -172,7 +172,7 @@ public FileDescriptorSource(@NonNull FileDescriptor fileDescriptor) {

@Override
GifInfoHandle open() throws IOException {
return new GifInfoHandle(mFd, false);
return new GifInfoHandle(mFd);
}
}

Expand All @@ -193,7 +193,7 @@ public InputStreamSource(@NonNull InputStream inputStream) {

@Override
GifInfoHandle open() throws IOException {
return new GifInfoHandle(inputStream, false);
return new GifInfoHandle(inputStream);
}
}

Expand All @@ -217,7 +217,7 @@ public ResourcesSource(@NonNull Resources resources, @RawRes @DrawableRes int re

@Override
GifInfoHandle open() throws IOException {
return new GifInfoHandle(mResources.openRawResourceFd(mResourceId), false);
return new GifInfoHandle(mResources.openRawResourceFd(mResourceId));
}
}

Expand All @@ -238,7 +238,7 @@ public AssetFileDescriptorSource(@NonNull AssetFileDescriptor assetFileDescripto

@Override
GifInfoHandle open() throws IOException {
return new GifInfoHandle(mAssetFileDescriptor, false);
return new GifInfoHandle(mAssetFileDescriptor);
}
}

Expand Down
Loading

0 comments on commit 81117e4

Please sign in to comment.