|
23 | 23 | import com.bumptech.glide.provider.ResourceDecoderRegistry;
|
24 | 24 | import com.bumptech.glide.provider.ResourceEncoderRegistry;
|
25 | 25 | import com.bumptech.glide.util.pool.FactoryPools;
|
| 26 | + |
26 | 27 | import java.util.ArrayList;
|
27 | 28 | import java.util.Collections;
|
28 | 29 | import java.util.List;
|
@@ -65,11 +66,24 @@ public Registry() {
|
65 | 66 | * {@link java.io.FileInputStream} and any other subclass.
|
66 | 67 | *
|
67 | 68 | * <p>If multiple {@link Encoder}s are registered for the same type or super type, the
|
68 |
| - * {@link Encoder} that is registered first will be used. As a result, it's not currently possible |
69 |
| - * to replace Glide's default {@link Encoder}s. |
| 69 | + * {@link Encoder} that is registered first will be used. |
70 | 70 | */
|
71 | 71 | public <Data> Registry register(Class<Data> dataClass, Encoder<Data> encoder) {
|
72 |
| - encoderRegistry.add(dataClass, encoder); |
| 72 | + encoderRegistry.append(dataClass, encoder); |
| 73 | + return this; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Prepends the given {@link Encoder} into the list of available {@link Encoder}s |
| 78 | + * so that it is attempted before all later and default {@link Encoder}s for the given |
| 79 | + * data class. |
| 80 | + * |
| 81 | + * <p>This method allows you to replace the default {@link Encoder} because it ensures |
| 82 | + * the registered {@link Encoder} will run first. If multiple {@link Encoder}s are registered for |
| 83 | + * the same type or super type, the {@link Encoder} that is registered first will be used. |
| 84 | + */ |
| 85 | + public <Data> Registry prepend(Class<Data> dataClass, Encoder<Data> encoder) { |
| 86 | + encoderRegistry.prepend(dataClass, encoder); |
73 | 87 | return this;
|
74 | 88 | }
|
75 | 89 |
|
@@ -139,12 +153,30 @@ public <Data, TResource> Registry prepend(
|
139 | 153 | * {@link com.bumptech.glide.load.resource.gif.GifDrawable} and any other subclass.
|
140 | 154 | *
|
141 | 155 | * <p>If multiple {@link ResourceEncoder}s are registered for the same type or super type, the
|
142 |
| - * {@link ResourceEncoder} that is registered first will be used. As a result, it's not currently |
143 |
| - * possible to replace Glide's default {@link ResourceEncoder}s. |
| 156 | + * {@link ResourceEncoder} that is registered first will be used. |
144 | 157 | */
|
145 | 158 | public <TResource> Registry register(Class<TResource> resourceClass,
|
146 | 159 | ResourceEncoder<TResource> encoder) {
|
147 |
| - resourceEncoderRegistry.add(resourceClass, encoder); |
| 160 | + resourceEncoderRegistry.append(resourceClass, encoder); |
| 161 | + return this; |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Registers a new {@link com.bumptech.glide.load.data.DataRewinder.Factory} to handle a |
| 166 | + * non-default data type that can be rewind to allow for efficient reads of file headers. |
| 167 | + * |
| 168 | + * Prepends the given {@link ResourceEncoder} into the list of available {@link ResourceEncoder}s |
| 169 | + * so that it is attempted before all later and default {@link ResourceEncoder}s for the given |
| 170 | + * data type. |
| 171 | + * |
| 172 | + * <p>This method allows you to replace the default {@link ResourceEncoder} because it ensures |
| 173 | + * the registered {@link ResourceEncoder} will run first. If multiple {@link ResourceEncoder}s are |
| 174 | + * registered for the same type or super type, the {@link ResourceEncoder} that is registered |
| 175 | + * first will be used. |
| 176 | + */ |
| 177 | + public <TResource> Registry prepend(Class<TResource> resourceClass, |
| 178 | + ResourceEncoder<TResource> encoder) { |
| 179 | + resourceEncoderRegistry.prepend(resourceClass, encoder); |
148 | 180 | return this;
|
149 | 181 | }
|
150 | 182 |
|
|
0 commit comments