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

Commit 82409585 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow chaining ImageDecoder's setters"

parents f10f40b0 5f7e948a
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -13605,16 +13605,16 @@ package android.graphics {
    method public static android.graphics.drawable.Drawable decodeDrawable(android.graphics.ImageDecoder.Source, android.graphics.ImageDecoder.OnHeaderDecodedListener) throws java.io.IOException;
    method public static android.graphics.drawable.Drawable decodeDrawable(android.graphics.ImageDecoder.Source) throws java.io.IOException;
    method public android.util.Size getSampledSize(int);
    method public void setAllocator(int);
    method public void setAsAlphaMask(boolean);
    method public void setConserveMemory(boolean);
    method public void setCrop(android.graphics.Rect);
    method public void setMutable(boolean);
    method public void setOnPartialImageListener(android.graphics.ImageDecoder.OnPartialImageListener);
    method public void setPostProcessor(android.graphics.PostProcessor);
    method public void setRequireUnpremultiplied(boolean);
    method public void setResize(int, int);
    method public void setResize(int);
    method public android.graphics.ImageDecoder setAllocator(int);
    method public android.graphics.ImageDecoder setAsAlphaMask(boolean);
    method public android.graphics.ImageDecoder setConserveMemory(boolean);
    method public android.graphics.ImageDecoder setCrop(android.graphics.Rect);
    method public android.graphics.ImageDecoder setMutable(boolean);
    method public android.graphics.ImageDecoder setOnPartialImageListener(android.graphics.ImageDecoder.OnPartialImageListener);
    method public android.graphics.ImageDecoder setPostProcessor(android.graphics.PostProcessor);
    method public android.graphics.ImageDecoder setRequireUnpremultiplied(boolean);
    method public android.graphics.ImageDecoder setResize(int, int);
    method public android.graphics.ImageDecoder setResize(int);
    field public static final int ALLOCATOR_DEFAULT = 0; // 0x0
    field public static final int ALLOCATOR_HARDWARE = 3; // 0x3
    field public static final int ALLOCATOR_SHARED_MEMORY = 2; // 0x2
+49 −19
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.graphics;
import static android.system.OsConstants.SEEK_CUR;
import static android.system.OsConstants.SEEK_SET;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -52,8 +54,6 @@ import java.lang.annotation.Retention;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean;

import static java.lang.annotation.RetentionPolicy.SOURCE;

/**
 *  Class for decoding images as {@link Bitmap}s or {@link Drawable}s.
 */
@@ -690,8 +690,9 @@ public final class ImageDecoder implements AutoCloseable {
     *
     *  @param width must be greater than 0.
     *  @param height must be greater than 0.
     *  @return this object for chaining.
     */
    public void setResize(int width, int height) {
    public ImageDecoder setResize(int width, int height) {
        if (width <= 0 || height <= 0) {
            throw new IllegalArgumentException("Dimensions must be positive! "
                    + "provided (" + width + ", " + height + ")");
@@ -699,6 +700,7 @@ public final class ImageDecoder implements AutoCloseable {

        mDesiredWidth = width;
        mDesiredHeight = height;
        return this;
    }

    /**
@@ -708,10 +710,11 @@ public final class ImageDecoder implements AutoCloseable {
     *  {@link #getSampledSize} to {@link #setResize(int, int)}.</p>
     *
     *  @param sampleSize Sampling rate of the encoded image.
     *  @return this object for chaining.
     */
    public void setResize(int sampleSize) {
    public ImageDecoder setResize(int sampleSize) {
        Size size = this.getSampledSize(sampleSize);
        this.setResize(size.getWidth(), size.getHeight());
        return this.setResize(size.getWidth(), size.getHeight());
    }

    private boolean requestedResize() {
@@ -767,18 +770,20 @@ public final class ImageDecoder implements AutoCloseable {
     *  This is ignored for animated drawables.
     *
     *  @param allocator Type of allocator to use.
     *  @return this object for chaining.
     */
    public void setAllocator(@Allocator int allocator) {
    public ImageDecoder setAllocator(@Allocator int allocator) {
        if (allocator < ALLOCATOR_DEFAULT || allocator > ALLOCATOR_HARDWARE) {
            throw new IllegalArgumentException("invalid allocator " + allocator);
        }
        mAllocator = allocator;
        return this;
    }

    /**
     *  Specify whether the {@link Bitmap} should have unpremultiplied pixels.
     *
     *  By default, ImageDecoder will create a {@link Bitmap} with
     *  <p>By default, ImageDecoder will create a {@link Bitmap} with
     *  premultiplied pixels, which is required for drawing with the
     *  {@link android.view.View} system (i.e. to a {@link Canvas}). Calling
     *  this method with a value of {@code true} will result in
@@ -786,9 +791,13 @@ public final class ImageDecoder implements AutoCloseable {
     *  pixels. See {@link Bitmap#isPremultiplied}. This is incompatible with
     *  {@link #decodeDrawable}; attempting to decode an unpremultiplied
     *  {@link Drawable} will throw an {@link java.lang.IllegalStateException}.
     *  </p>
     *
     *  @return this object for chaining.
     */
    public void setRequireUnpremultiplied(boolean requireUnpremultiplied) {
    public ImageDecoder setRequireUnpremultiplied(boolean requireUnpremultiplied) {
        mRequireUnpremultiplied = requireUnpremultiplied;
        return this;
    }

    /**
@@ -803,19 +812,25 @@ public final class ImageDecoder implements AutoCloseable {
     *  <p>For an animated image, the drawing commands drawn on the
     *  {@link Canvas} will be recorded immediately and then applied to each
     *  frame.</p>
     *
     *  @return this object for chaining.
     */
    public void setPostProcessor(@Nullable PostProcessor p) {
    public ImageDecoder setPostProcessor(@Nullable PostProcessor p) {
        mPostProcessor = p;
        return this;
    }

    /**
     *  Set (replace) the {@link OnPartialImageListener} on this object.
     *
     *  Will be called if there is an error in the input. Without one, a
     *  partial {@link Bitmap} will be created.
     *  <p>Will be called if there is an error in the input. Without one, an
     *  error will result in an Exception being thrown.</p>
     *
     *  @return this object for chaining.
     */
    public void setOnPartialImageListener(@Nullable OnPartialImageListener l) {
    public ImageDecoder setOnPartialImageListener(@Nullable OnPartialImageListener l) {
        mOnPartialImageListener = l;
        return this;
    }

    /**
@@ -829,9 +844,12 @@ public final class ImageDecoder implements AutoCloseable {
     *  <p>NOT intended as a replacement for
     *  {@link BitmapRegionDecoder#decodeRegion}. This supports all formats,
     *  but merely crops the output.</p>
     *
     *  @return this object for chaining.
     */
    public void setCrop(@Nullable Rect subset) {
    public ImageDecoder setCrop(@Nullable Rect subset) {
        mCropRect = subset;
        return this;
    }

    /**
@@ -840,10 +858,13 @@ public final class ImageDecoder implements AutoCloseable {
     *  If the image is a nine patch, this Rect will be set to the padding
     *  rectangle during decode. Otherwise it will not be modified.
     *
     *  @return this object for chaining.
     *
     *  @hide
     */
    public void setOutPaddingRect(@NonNull Rect outPadding) {
    public ImageDecoder setOutPaddingRect(@NonNull Rect outPadding) {
        mOutPaddingRect = outPadding;
        return this;
    }

    /**
@@ -861,25 +882,31 @@ public final class ImageDecoder implements AutoCloseable {
     *  which would require retrieving the Bitmap from the returned Drawable in
     *  order to modify. Attempting to decode a mutable {@link Drawable} will
     *  throw an {@link java.lang.IllegalStateException}.</p>
     *
     *  @return this object for chaining.
     */
    public void setMutable(boolean mutable) {
    public ImageDecoder setMutable(boolean mutable) {
        mMutable = mutable;
        return this;
    }

    /**
     *  Specify whether to potentially save RAM at the expense of quality.
     *
     *  Setting this to {@code true} may result in a {@link Bitmap} with a
     *  <p>Setting this to {@code true} may result in a {@link Bitmap} with a
     *  denser {@link Bitmap.Config}, depending on the image. For example, an
     *  opaque {@link Bitmap} with 8 bits or precision for each of its red,
     *  green and blue components would decode to
     *  {@link Bitmap.Config#ARGB_8888} by default, but setting this to
     *  {@code true} will result in decoding to {@link Bitmap.Config#RGB_565}.
     *  This necessarily lowers the quality of the output, but saves half
     *  the memory used.
     *  the memory used.</p>
     *
     *  @return this object for chaining.
     */
    public void setConserveMemory(boolean conserveMemory) {
    public ImageDecoder setConserveMemory(boolean conserveMemory) {
        mConserveMemory = conserveMemory;
        return this;
    }

    /**
@@ -893,9 +920,12 @@ public final class ImageDecoder implements AutoCloseable {
     *  combine them will result in {@link #decodeDrawable}/
     *  {@link #decodeBitmap} throwing an
     *  {@link java.lang.IllegalStateException}.</p>
     *
     *  @return this object for chaining.
     */
    public void setAsAlphaMask(boolean asAlphaMask) {
    public ImageDecoder setAsAlphaMask(boolean asAlphaMask) {
        mAsAlphaMask = asAlphaMask;
        return this;
    }

    @Override