@nativescript-community/ui-image 4.2.1 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,39 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.3.2](https://github.com/nativescript-community/ui-image/compare/v4.3.1...v4.3.2) (2022-07-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **image:** imageRotation scaling fix ([2f12172](https://github.com/nativescript-community/ui-image/commit/2f12172c022c9e6122420763a43b68a2bc137503))
12
+
13
+
14
+
15
+
16
+
17
+ ## [4.3.1](https://github.com/nativescript-community/ui-image/compare/v4.3.0...v4.3.1) (2022-07-14)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **image:** make imageRotation work in ListView ([58913bd](https://github.com/nativescript-community/ui-image/commit/58913bde275284ed704fac07b4154c11090bc7b9))
23
+
24
+
25
+
26
+
27
+
28
+ # [4.3.0](https://github.com/nativescript-community/ui-image/compare/v4.2.1...v4.3.0) (2022-07-13)
29
+
30
+
31
+ ### Features
32
+
33
+ * **image:** imageRotation support (android only for now) ([1f5b597](https://github.com/nativescript-community/ui-image/commit/1f5b59749317ad73e03961c280206fa2523d0b8d))
34
+
35
+
36
+
37
+
38
+
6
39
  ## [4.2.1](https://github.com/nativescript-community/ui-image/compare/v4.2.0...v4.2.1) (2022-07-08)
7
40
 
8
41
  **Note:** Version bump only for package @nativescript-community/ui-image
package/index-common.d.ts CHANGED
@@ -65,6 +65,7 @@ export declare class ImageBase extends View {
65
65
  failureImageUri: string;
66
66
  stretch: ScaleType;
67
67
  fadeDuration: number;
68
+ imageRotation: number;
68
69
  backgroundUri: string;
69
70
  progressiveRenderingEnabled: boolean;
70
71
  localThumbnailPreviewsEnabled: boolean;
@@ -100,6 +101,7 @@ export declare class ImageBase extends View {
100
101
  static roundAsCircleProperty: Property<ImageBase, boolean>;
101
102
  static blurRadiusProperty: Property<ImageBase, number>;
102
103
  static blurDownSamplingProperty: Property<ImageBase, number>;
104
+ static imageRotationProperty: Property<ImageBase, number>;
103
105
  static autoPlayAnimationsProperty: Property<ImageBase, boolean>;
104
106
  static tapToRetryEnabledProperty: Property<ImageBase, boolean>;
105
107
  static aspectRatioProperty: Property<ImageBase, number>;
package/index-common.js CHANGED
@@ -138,6 +138,7 @@ ImageBase.progressBarColorProperty = new Property({ name: 'progressBarColor', de
138
138
  ImageBase.roundAsCircleProperty = new Property({ name: 'roundAsCircle', valueConverter: booleanConverter, affectsLayout: isAndroid });
139
139
  ImageBase.blurRadiusProperty = new Property({ name: 'blurRadius', valueConverter: (v) => parseFloat(v) });
140
140
  ImageBase.blurDownSamplingProperty = new Property({ name: 'blurDownSampling', valueConverter: (v) => parseFloat(v) });
141
+ ImageBase.imageRotationProperty = new Property({ name: 'imageRotation', valueConverter: (v) => parseFloat(v) });
141
142
  ImageBase.autoPlayAnimationsProperty = new Property({ name: 'autoPlayAnimations', valueConverter: booleanConverter });
142
143
  ImageBase.tapToRetryEnabledProperty = new Property({ name: 'tapToRetryEnabled', valueConverter: booleanConverter });
143
144
  ImageBase.aspectRatioProperty = new Property({ name: 'aspectRatio', affectsLayout: true, valueConverter: (v) => parseFloat(v) });
@@ -187,6 +188,7 @@ ImageBase.roundBottomLeftRadiusProperty.register(ImageBase);
187
188
  ImageBase.roundBottomRightRadiusProperty.register(ImageBase);
188
189
  ImageBase.blurRadiusProperty.register(ImageBase);
189
190
  ImageBase.blurDownSamplingProperty.register(ImageBase);
191
+ ImageBase.imageRotationProperty.register(ImageBase);
190
192
  ImageBase.autoPlayAnimationsProperty.register(ImageBase);
191
193
  ImageBase.tapToRetryEnabledProperty.register(ImageBase);
192
194
  ImageBase.aspectRatioProperty.register(ImageBase);
package/index.android.js CHANGED
@@ -310,6 +310,12 @@ export class Img extends ImageBase {
310
310
  [ImageBase.roundTopLeftRadiusProperty.setNative]() {
311
311
  this.updateHierarchy();
312
312
  }
313
+ [ImageBase.imageRotationProperty.setNative](value) {
314
+ var _e;
315
+ const scaleType = this.nativeImageViewProtected.getHierarchy().getActualImageScaleType();
316
+ (_e = scaleType['setImageRotation']) === null || _e === void 0 ? void 0 : _e.call(scaleType, value);
317
+ this.nativeImageViewProtected.invalidate();
318
+ }
313
319
  [ImageBase.roundTopRightRadiusProperty.setNative]() {
314
320
  this.updateHierarchy();
315
321
  }
@@ -566,7 +572,7 @@ export class Img extends ImageBase {
566
572
  builder.setPlaceholderImage(placeholderImageDrawable, this.stretch);
567
573
  }
568
574
  if (this.stretch) {
569
- builder.setActualImageScaleType(this.stretch);
575
+ builder.setActualImageScaleType(this.stretch, this.imageRotation);
570
576
  }
571
577
  if (this.fadeDuration) {
572
578
  builder.setFadeDuration(this.fadeDuration);
@@ -702,11 +708,15 @@ class GenericDraweeHierarchyBuilder {
702
708
  }
703
709
  return this;
704
710
  }
705
- setActualImageScaleType(scaleType) {
711
+ setActualImageScaleType(scaleType, imageRotation) {
706
712
  if (!this.nativeBuilder) {
707
713
  return this;
708
714
  }
709
- this.nativeBuilder.setActualImageScaleType(getScaleType(scaleType));
715
+ const nativeScaleType = getScaleType(scaleType);
716
+ if (nativeScaleType['setImageRotation']) {
717
+ nativeScaleType['setImageRotation'](imageRotation);
718
+ }
719
+ this.nativeBuilder.setActualImageScaleType(nativeScaleType);
710
720
  return this;
711
721
  }
712
722
  build() {
@@ -762,24 +772,24 @@ function getScaleType(scaleType) {
762
772
  if (isString(scaleType)) {
763
773
  switch (scaleType) {
764
774
  case ScaleType.Center:
765
- return com.facebook.drawee.drawable.ScalingUtils.ScaleType.CENTER;
775
+ return new com.nativescript.image.ScalingUtils.ScaleTypeCenter();
766
776
  case ScaleType.AspectFill:
767
777
  case ScaleType.CenterCrop:
768
- return com.facebook.drawee.drawable.ScalingUtils.ScaleType.CENTER_CROP;
778
+ return new com.nativescript.image.ScalingUtils.ScaleTypeCenterCrop();
769
779
  case ScaleType.CenterInside:
770
- return com.facebook.drawee.drawable.ScalingUtils.ScaleType.CENTER_INSIDE;
780
+ return new com.nativescript.image.ScalingUtils.ScaleTypeCenterInside();
771
781
  case ScaleType.FitCenter:
772
782
  case ScaleType.AspectFit:
773
- return com.facebook.drawee.drawable.ScalingUtils.ScaleType.FIT_CENTER;
783
+ return new com.nativescript.image.ScalingUtils.ScaleTypeFitCenter();
774
784
  case ScaleType.FitEnd:
775
- return com.facebook.drawee.drawable.ScalingUtils.ScaleType.FIT_END;
785
+ return new com.nativescript.image.ScalingUtils.ScaleTypeFitEnd();
776
786
  case ScaleType.FitStart:
777
- return com.facebook.drawee.drawable.ScalingUtils.ScaleType.FIT_START;
787
+ return new com.nativescript.image.ScalingUtils.ScaleTypeFitStart();
778
788
  case ScaleType.Fill:
779
789
  case ScaleType.FitXY:
780
- return com.facebook.drawee.drawable.ScalingUtils.ScaleType.FIT_XY;
790
+ return new com.nativescript.image.ScalingUtils.ScaleTypeFitXY();
781
791
  case ScaleType.FocusCrop:
782
- return com.facebook.drawee.drawable.ScalingUtils.ScaleType.FOCUS_CROP;
792
+ return new com.nativescript.image.ScalingUtils.ScaleTypeFocusCrop();
783
793
  default:
784
794
  break;
785
795
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript-community/ui-image",
3
- "version": "4.2.1",
3
+ "version": "4.3.2",
4
4
  "description": "Advanced and efficient image display plugin which uses Fresco (Android) and SDWebImage (iOS) to implement caching, placeholders, image effects, and much more.",
5
5
  "main": "./index",
6
6
  "sideEffects": false,
@@ -44,5 +44,5 @@
44
44
  },
45
45
  "license": "Apache-2.0",
46
46
  "readmeFilename": "README.md",
47
- "gitHead": "7ae707fd4b614e66d757d0f54a207f311702e826"
47
+ "gitHead": "0c463c971b84b168d620d8b500025b3b908e9710"
48
48
  }
@@ -0,0 +1,492 @@
1
+ package com.nativescript.image;
2
+
3
+ import android.graphics.Matrix;
4
+ import android.graphics.PointF;
5
+ import android.graphics.Rect;
6
+ import android.util.Log;
7
+
8
+ /** Performs scale type calculations. */
9
+ public class ScalingUtils {
10
+
11
+ /**
12
+ * Options for scaling the child bounds to the parent bounds.
13
+ *
14
+ * <p>Similar to {@link android.widget.ImageView.ScaleType}, but ScaleType.MATRIX is not
15
+ * supported. To use matrix scaling, use a {@link MatrixDrawable}. An additional scale type
16
+ * (FOCUS_CROP) is provided.
17
+ *
18
+ * <p>
19
+ */
20
+ public interface ScaleType {
21
+
22
+ /**
23
+ * Scales width and height independently, so that the child matches the parent exactly. This may
24
+ * change the aspect ratio of the child.
25
+ */
26
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType FIT_XY = ScaleTypeFitXY.INSTANCE;
27
+
28
+ /**
29
+ * Scales the child so that the child's width fits exactly. The height will be cropped if it
30
+ * exceeds parent's bounds. Aspect ratio is preserved. Child is centered within the parent's
31
+ * bounds.
32
+ */
33
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType FIT_X = ScaleTypeFitX.INSTANCE;
34
+
35
+ /**
36
+ * Scales the child so that the child's height fits exactly. The width will be cropped if it
37
+ * exceeds parent's bounds. Aspect ratio is preserved. Child is centered within the parent's
38
+ * bounds.
39
+ */
40
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType FIT_Y = ScaleTypeFitY.INSTANCE;
41
+
42
+ /**
43
+ * Scales the child so that it fits entirely inside the parent. At least one dimension (width or
44
+ * height) will fit exactly. Aspect ratio is preserved. Child is aligned to the top-left corner
45
+ * of the parent.
46
+ */
47
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType FIT_START = ScaleTypeFitStart.INSTANCE;
48
+
49
+ /**
50
+ * Scales the child so that it fits entirely inside the parent. At least one dimension (width or
51
+ * height) will fit exactly. Aspect ratio is preserved. Child is centered within the parent's
52
+ * bounds.
53
+ */
54
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType FIT_CENTER = ScaleTypeFitCenter.INSTANCE;
55
+
56
+ /**
57
+ * Scales the child so that it fits entirely inside the parent. At least one dimension (width or
58
+ * height) will fit exactly. Aspect ratio is preserved. Child is aligned to the bottom-right
59
+ * corner of the parent.
60
+ */
61
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType FIT_END = ScaleTypeFitEnd.INSTANCE;
62
+
63
+ /** Performs no scaling. Child is centered within parent's bounds. */
64
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType CENTER = ScaleTypeCenter.INSTANCE;
65
+
66
+ /**
67
+ * Scales the child so that it fits entirely inside the parent. Unlike FIT_CENTER, if the child
68
+ * is smaller, no up-scaling will be performed. Aspect ratio is preserved. Child is centered
69
+ * within parent's bounds.
70
+ */
71
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType CENTER_INSIDE = ScaleTypeCenterInside.INSTANCE;
72
+
73
+ /**
74
+ * Scales the child so that both dimensions will be greater than or equal to the corresponding
75
+ * dimension of the parent. At least one dimension (width or height) will fit exactly. Child is
76
+ * centered within parent's bounds.
77
+ */
78
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType CENTER_CROP = ScaleTypeCenterCrop.INSTANCE;
79
+
80
+ /**
81
+ * Scales the child so that both dimensions will be greater than or equal to the corresponding
82
+ * dimension of the parent. At least one dimension (width or height) will fit exactly. The
83
+ * child's focus point will be centered within the parent's bounds as much as possible without
84
+ * leaving empty space. It is guaranteed that the focus point will be visible and centered as
85
+ * much as possible. If the focus point is set to (0.5f, 0.5f), result will be equivalent to
86
+ * CENTER_CROP.
87
+ */
88
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType FOCUS_CROP = ScaleTypeFocusCrop.INSTANCE;
89
+
90
+ /**
91
+ * Scales the child so that it fits entirely inside the parent. At least one dimension (width or
92
+ * height) will fit exactly. Aspect ratio is preserved. Child is aligned to the bottom-left
93
+ * corner of the parent.
94
+ */
95
+ com.facebook.drawee.drawable.ScalingUtils.ScaleType FIT_BOTTOM_START = ScaleTypeFitBottomStart.INSTANCE;
96
+
97
+ /**
98
+ * Gets transformation matrix based on the scale type.
99
+ *
100
+ * @param outTransform out matrix to store result
101
+ * @param parentBounds parent bounds
102
+ * @param childWidth child width
103
+ * @param childHeight child height
104
+ * @param focusX focus point x coordinate, relative [0...1]
105
+ * @param focusY focus point y coordinate, relative [0...1]
106
+ * @return same reference to the out matrix for convenience
107
+ */
108
+ Matrix getTransform(
109
+ Matrix outTransform,
110
+ Rect parentBounds,
111
+ int childWidth,
112
+ int childHeight,
113
+ float focusX,
114
+ float focusY);
115
+ }
116
+
117
+
118
+
119
+ /** A convenience base class that has some common logic. */
120
+ public abstract static class AbstractScaleType implements com.facebook.drawee.drawable.ScalingUtils.ScaleType, com.facebook.drawee.drawable.ScalingUtils.StatefulScaleType {
121
+ protected Matrix _imageMatrix = null;
122
+ protected float _imageRotation = 0;
123
+ public void setImageMatrix(Matrix matrix) {
124
+ _imageMatrix = matrix;
125
+ }
126
+ public void setImageRotation(float rotation) {
127
+ _imageRotation = rotation;
128
+ }
129
+
130
+ @Override
131
+ public Object getState() {
132
+ if (_imageMatrix != null) {
133
+ return _imageMatrix;
134
+ }
135
+ return _imageRotation;
136
+ }
137
+ @Override
138
+ public Matrix getTransform(
139
+ Matrix outTransform,
140
+ Rect parentRect,
141
+ int childWidth,
142
+ int childHeight,
143
+ float focusX,
144
+ float focusY) {
145
+ float sX = (float) parentRect.width() / (float) childWidth;
146
+ float sY = (float) parentRect.height() / (float) childHeight;
147
+ float rotationDelta = (90 - (_imageRotation % 180))/90.0f;
148
+ if (rotationDelta != 1) {
149
+ float destSX = (float) parentRect.width() / (float) childHeight;
150
+ float destSY = (float) parentRect.height() / (float) childWidth;
151
+ if (rotationDelta < 0) {
152
+ sX = destSX + rotationDelta * (destSX - sX);
153
+ sY = destSY + rotationDelta * (destSY - sY);
154
+ } else {
155
+ sX = sX + (1 - rotationDelta) * (destSX - sX);
156
+ sY = sY + (1 - rotationDelta) * (destSY - sY);
157
+ }
158
+
159
+ }
160
+ getTransformImpl(outTransform, parentRect, childWidth, childHeight, focusX, focusY, sX, sY);
161
+ if (_imageMatrix != null) {
162
+ outTransform.preConcat(_imageMatrix);
163
+ } else if (_imageRotation != 0) {
164
+ outTransform.preRotate(_imageRotation, childWidth / 2.0f, childHeight / 2.0f);
165
+ }
166
+
167
+ return outTransform;
168
+ }
169
+
170
+ public abstract void getTransformImpl(
171
+ Matrix outTransform,
172
+ Rect parentRect,
173
+ int childWidth,
174
+ int childHeight,
175
+ float focusX,
176
+ float focusY,
177
+ float scaleX,
178
+ float scaleY);
179
+ }
180
+
181
+ public static class ScaleTypeFitXY extends AbstractScaleType {
182
+
183
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitXY();
184
+
185
+ @Override
186
+ public void getTransformImpl(
187
+ Matrix outTransform,
188
+ Rect parentRect,
189
+ int childWidth,
190
+ int childHeight,
191
+ float focusX,
192
+ float focusY,
193
+ float scaleX,
194
+ float scaleY) {
195
+ float dx = parentRect.left;
196
+ float dy = parentRect.top;
197
+ outTransform.setScale(scaleX, scaleY);
198
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
199
+ }
200
+
201
+ @Override
202
+ public String toString() {
203
+ return "fit_xy";
204
+ }
205
+ }
206
+
207
+ public static class ScaleTypeFitStart extends AbstractScaleType {
208
+
209
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitStart();
210
+
211
+ @Override
212
+ public void getTransformImpl(
213
+ Matrix outTransform,
214
+ Rect parentRect,
215
+ int childWidth,
216
+ int childHeight,
217
+ float focusX,
218
+ float focusY,
219
+ float scaleX,
220
+ float scaleY) {
221
+ float scale = Math.min(scaleX, scaleY);
222
+ float dx = parentRect.left;
223
+ float dy = parentRect.top;
224
+ outTransform.setScale(scale, scale);
225
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
226
+ }
227
+
228
+ @Override
229
+ public String toString() {
230
+ return "fit_start";
231
+ }
232
+ }
233
+
234
+ public static class ScaleTypeFitBottomStart extends AbstractScaleType {
235
+
236
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitBottomStart();
237
+
238
+ @Override
239
+ public void getTransformImpl(
240
+ Matrix outTransform,
241
+ Rect parentRect,
242
+ int childWidth,
243
+ int childHeight,
244
+ float focusX,
245
+ float focusY,
246
+ float scaleX,
247
+ float scaleY) {
248
+ float scale = Math.min(scaleX, scaleY);
249
+ float dx = parentRect.left;
250
+ float dy = parentRect.top + (parentRect.height() - childHeight * scale);
251
+ outTransform.setScale(scale, scale);
252
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
253
+ }
254
+
255
+ @Override
256
+ public String toString() {
257
+ return "fit_bottom_start";
258
+ }
259
+ }
260
+
261
+ public static class ScaleTypeFitCenter extends AbstractScaleType {
262
+
263
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitCenter();
264
+
265
+ @Override
266
+ public void getTransformImpl(
267
+ Matrix outTransform,
268
+ Rect parentRect,
269
+ int childWidth,
270
+ int childHeight,
271
+ float focusX,
272
+ float focusY,
273
+ float scaleX,
274
+ float scaleY) {
275
+ float scale = Math.min(scaleX, scaleY);
276
+ float dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
277
+ float dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
278
+ outTransform.setScale(scale, scale);
279
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
280
+ }
281
+
282
+ @Override
283
+ public String toString() {
284
+ return "fit_center";
285
+ }
286
+ }
287
+
288
+ public static class ScaleTypeFitEnd extends AbstractScaleType {
289
+
290
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitEnd();
291
+
292
+ @Override
293
+ public void getTransformImpl(
294
+ Matrix outTransform,
295
+ Rect parentRect,
296
+ int childWidth,
297
+ int childHeight,
298
+ float focusX,
299
+ float focusY,
300
+ float scaleX,
301
+ float scaleY) {
302
+ float scale = Math.min(scaleX, scaleY);
303
+ float dx = parentRect.left + (parentRect.width() - childWidth * scale);
304
+ float dy = parentRect.top + (parentRect.height() - childHeight * scale);
305
+ outTransform.setScale(scale, scale);
306
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
307
+ }
308
+
309
+ @Override
310
+ public String toString() {
311
+ return "fit_end";
312
+ }
313
+ }
314
+
315
+ public static class ScaleTypeCenter extends AbstractScaleType {
316
+
317
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeCenter();
318
+
319
+ @Override
320
+ public void getTransformImpl(
321
+ Matrix outTransform,
322
+ Rect parentRect,
323
+ int childWidth,
324
+ int childHeight,
325
+ float focusX,
326
+ float focusY,
327
+ float scaleX,
328
+ float scaleY) {
329
+ float dx = parentRect.left + (parentRect.width() - childWidth) * 0.5f;
330
+ float dy = parentRect.top + (parentRect.height() - childHeight) * 0.5f;
331
+ outTransform.setTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
332
+ }
333
+
334
+ @Override
335
+ public String toString() {
336
+ return "center";
337
+ }
338
+ }
339
+
340
+ public static class ScaleTypeCenterInside extends AbstractScaleType {
341
+
342
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeCenterInside();
343
+
344
+ @Override
345
+ public void getTransformImpl(
346
+ Matrix outTransform,
347
+ Rect parentRect,
348
+ int childWidth,
349
+ int childHeight,
350
+ float focusX,
351
+ float focusY,
352
+ float scaleX,
353
+ float scaleY) {
354
+ float scale = Math.min(Math.min(scaleX, scaleY), 1.0f);
355
+ float dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
356
+ float dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
357
+ outTransform.setScale(scale, scale);
358
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
359
+ }
360
+
361
+ @Override
362
+ public String toString() {
363
+ return "center_inside";
364
+ }
365
+ }
366
+
367
+ public static class ScaleTypeCenterCrop extends AbstractScaleType {
368
+
369
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeCenterCrop();
370
+
371
+ @Override
372
+ public void getTransformImpl(
373
+ Matrix outTransform,
374
+ Rect parentRect,
375
+ int childWidth,
376
+ int childHeight,
377
+ float focusX,
378
+ float focusY,
379
+ float scaleX,
380
+ float scaleY) {
381
+ float scale, dx, dy;
382
+ if (scaleY > scaleX) {
383
+ scale = scaleY;
384
+ dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
385
+ dy = parentRect.top;
386
+ } else {
387
+ scale = scaleX;
388
+ dx = parentRect.left;
389
+ dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
390
+ }
391
+ outTransform.setScale(scale, scale);
392
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
393
+ }
394
+
395
+ @Override
396
+ public String toString() {
397
+ return "center_crop";
398
+ }
399
+ }
400
+
401
+ public static class ScaleTypeFocusCrop extends AbstractScaleType {
402
+
403
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFocusCrop();
404
+
405
+ @Override
406
+ public void getTransformImpl(
407
+ Matrix outTransform,
408
+ Rect parentRect,
409
+ int childWidth,
410
+ int childHeight,
411
+ float focusX,
412
+ float focusY,
413
+ float scaleX,
414
+ float scaleY) {
415
+ float scale, dx, dy;
416
+ if (scaleY > scaleX) {
417
+ scale = scaleY;
418
+ dx = parentRect.width() * 0.5f - childWidth * scale * focusX;
419
+ dx = parentRect.left + Math.max(Math.min(dx, 0), parentRect.width() - childWidth * scale);
420
+ dy = parentRect.top;
421
+ } else {
422
+ scale = scaleX;
423
+ dx = parentRect.left;
424
+ dy = parentRect.height() * 0.5f - childHeight * scale * focusY;
425
+ dy = parentRect.top + Math.max(Math.min(dy, 0), parentRect.height() - childHeight * scale);
426
+ }
427
+ outTransform.setScale(scale, scale);
428
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
429
+ }
430
+
431
+ @Override
432
+ public String toString() {
433
+ return "focus_crop";
434
+ }
435
+ }
436
+
437
+ public static class ScaleTypeFitX extends AbstractScaleType {
438
+
439
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitX();
440
+
441
+ @Override
442
+ public void getTransformImpl(
443
+ Matrix outTransform,
444
+ Rect parentRect,
445
+ int childWidth,
446
+ int childHeight,
447
+ float focusX,
448
+ float focusY,
449
+ float scaleX,
450
+ float scaleY) {
451
+ float scale, dx, dy;
452
+ scale = scaleX;
453
+ dx = parentRect.left;
454
+ dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
455
+ outTransform.setScale(scale, scale);
456
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
457
+ }
458
+
459
+ @Override
460
+ public String toString() {
461
+ return "fit_x";
462
+ }
463
+ }
464
+
465
+ public static class ScaleTypeFitY extends AbstractScaleType {
466
+
467
+ public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitY();
468
+
469
+ @Override
470
+ public void getTransformImpl(
471
+ Matrix outTransform,
472
+ Rect parentRect,
473
+ int childWidth,
474
+ int childHeight,
475
+ float focusX,
476
+ float focusY,
477
+ float scaleX,
478
+ float scaleY) {
479
+ float scale, dx, dy;
480
+ scale = scaleY;
481
+ dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
482
+ dy = parentRect.top;
483
+ outTransform.setScale(scale, scale);
484
+ outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
485
+ }
486
+
487
+ @Override
488
+ public String toString() {
489
+ return "fit_y";
490
+ }
491
+ }
492
+ }
Binary file