Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9aa8565 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Make OnHeaderDecodedListener NonNull

Bug: 73788928
Test: No change in behavior; no new tests.

There is already an overload for both decodeDrawable and decodeBitmap
that allows not using an OnHeaderDecodedListener, so require calls to
the method that includes a parameter for it to contain a non-null
version.

Throw an exception if OnHeaderDecodedListener is null. Move
implementation to Impl methods to share code without lint warnings.
Rename the non-static decodeBitmap to decodeBitmapInternal, to
distinguish it from the others.

Change-Id: I12c0a35786d8d1267044ac09b5c9203cdfb7175a
parent b60ca84e
Loading
Loading
Loading
Loading
+29 −11
Original line number Diff line number Diff line
@@ -981,7 +981,7 @@ public final class ImageDecoder implements AutoCloseable {
    }

    @NonNull
    private Bitmap decodeBitmap() throws IOException {
    private Bitmap decodeBitmapInternal() throws IOException {
        checkState();
        // nDecodeBitmap calls onPartialImage only if mOnPartialImageListener
        // exists
@@ -1012,15 +1012,24 @@ public final class ImageDecoder implements AutoCloseable {
     *
     *  @param src representing the encoded image.
     *  @param listener for learning the {@link ImageInfo} and changing any
     *      default settings on the {@code ImageDecoder}. If not {@code null},
     *      this will be called on the same thread as {@code decodeDrawable}
     *      before that method returns.
     *      default settings on the {@code ImageDecoder}. This will be called on
     *      the same thread as {@code decodeDrawable} before that method returns.
     *  @return Drawable for displaying the image.
     *  @throws IOException if {@code src} is not found, is an unsupported
     *      format, or cannot be decoded for any reason.
     */
    @NonNull
    public static Drawable decodeDrawable(@NonNull Source src,
            @NonNull OnHeaderDecodedListener listener) throws IOException {
        if (listener == null) {
            throw new IllegalArgumentException("listener cannot be null! "
                    + "Use decodeDrawable(Source) to not have a listener");
        }
        return decodeDrawableImpl(src, listener);
    }

    @NonNull
    private static Drawable decodeDrawableImpl(@NonNull Source src,
            @Nullable OnHeaderDecodedListener listener) throws IOException {
        try (ImageDecoder decoder = src.createImageDecoder()) {
            decoder.mSource = src;
@@ -1057,7 +1066,7 @@ public final class ImageDecoder implements AutoCloseable {
                return d;
            }

            Bitmap bm = decoder.decodeBitmap();
            Bitmap bm = decoder.decodeBitmapInternal();
            bm.setDensity(srcDensity);

            Resources res = src.getResources();
@@ -1084,7 +1093,7 @@ public final class ImageDecoder implements AutoCloseable {
    @NonNull
    public static Drawable decodeDrawable(@NonNull Source src)
            throws IOException {
        return decodeDrawable(src, null);
        return decodeDrawableImpl(src, null);
    }

    /**
@@ -1092,15 +1101,24 @@ public final class ImageDecoder implements AutoCloseable {
     *
     *  @param src representing the encoded image.
     *  @param listener for learning the {@link ImageInfo} and changing any
     *      default settings on the {@code ImageDecoder}. If not {@code null},
     *      this will be called on the same thread as {@code decodeBitmap}
     *      before that method returns.
     *      default settings on the {@code ImageDecoder}. This will be called on
     *      the same thread as {@code decodeBitmap} before that method returns.
     *  @return Bitmap containing the image.
     *  @throws IOException if {@code src} is not found, is an unsupported
     *      format, or cannot be decoded for any reason.
     */
    @NonNull
    public static Bitmap decodeBitmap(@NonNull Source src,
            @NonNull OnHeaderDecodedListener listener) throws IOException {
        if (listener == null) {
            throw new IllegalArgumentException("listener cannot be null! "
                    + "Use decodeBitmap(Source) to not have a listener");
        }
        return decodeBitmapImpl(src, listener);
    }

    @NonNull
    private static Bitmap decodeBitmapImpl(@NonNull Source src,
            @Nullable OnHeaderDecodedListener listener) throws IOException {
        try (ImageDecoder decoder = src.createImageDecoder()) {
            decoder.mSource = src;
@@ -1109,7 +1127,7 @@ public final class ImageDecoder implements AutoCloseable {
            // this call potentially manipulates the decoder so it must be performed prior to
            // decoding the bitmap
            final int srcDensity = computeDensity(src, decoder);
            Bitmap bm = decoder.decodeBitmap();
            Bitmap bm = decoder.decodeBitmapInternal();
            bm.setDensity(srcDensity);

            Rect padding = decoder.mOutPaddingRect;
@@ -1167,7 +1185,7 @@ public final class ImageDecoder implements AutoCloseable {
     */
    @NonNull
    public static Bitmap decodeBitmap(@NonNull Source src) throws IOException {
        return decodeBitmap(src, null);
        return decodeBitmapImpl(src, null);
    }

    /**