@nativescript-community/ui-image 4.2.1 → 4.3.0
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,17 @@
|
|
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.0](https://github.com/nativescript-community/ui-image/compare/v4.2.1...v4.3.0) (2022-07-13)
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* **image:** imageRotation support (android only for now) ([1f5b597](https://github.com/nativescript-community/ui-image/commit/1f5b59749317ad73e03961c280206fa2523d0b8d))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
6
17
|
## [4.2.1](https://github.com/nativescript-community/ui-image/compare/v4.2.0...v4.2.1) (2022-07-08)
|
7
18
|
|
8
19
|
**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
|
-
|
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.
|
775
|
+
return com.nativescript.image.ScalingUtils.ScaleType.CENTER;
|
766
776
|
case ScaleType.AspectFill:
|
767
777
|
case ScaleType.CenterCrop:
|
768
|
-
return com.
|
778
|
+
return com.nativescript.image.ScalingUtils.ScaleType.CENTER_CROP;
|
769
779
|
case ScaleType.CenterInside:
|
770
|
-
return com.
|
780
|
+
return com.nativescript.image.ScalingUtils.ScaleType.CENTER_INSIDE;
|
771
781
|
case ScaleType.FitCenter:
|
772
782
|
case ScaleType.AspectFit:
|
773
|
-
return com.
|
783
|
+
return com.nativescript.image.ScalingUtils.ScaleType.FIT_CENTER;
|
774
784
|
case ScaleType.FitEnd:
|
775
|
-
return com.
|
785
|
+
return com.nativescript.image.ScalingUtils.ScaleType.FIT_END;
|
776
786
|
case ScaleType.FitStart:
|
777
|
-
return com.
|
787
|
+
return com.nativescript.image.ScalingUtils.ScaleType.FIT_START;
|
778
788
|
case ScaleType.Fill:
|
779
789
|
case ScaleType.FitXY:
|
780
|
-
return com.
|
790
|
+
return com.nativescript.image.ScalingUtils.ScaleType.FIT_XY;
|
781
791
|
case ScaleType.FocusCrop:
|
782
|
-
return com.
|
792
|
+
return com.nativescript.image.ScalingUtils.ScaleType.FOCUS_CROP;
|
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.
|
3
|
+
"version": "4.3.0",
|
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": "
|
47
|
+
"gitHead": "33aa9b9b923101c0c3f37f22a3ebaf245d6aa91e"
|
48
48
|
}
|
@@ -0,0 +1,487 @@
|
|
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 = _imageRotation % 180;
|
148
|
+
if (rotationDelta != 0) {
|
149
|
+
float destSX = (float) parentRect.width() / (float) childHeight;
|
150
|
+
float destSY = (float) parentRect.height() / (float) childWidth;
|
151
|
+
final float pos = Math.abs(rotationDelta)/90.0f;
|
152
|
+
sX = sX + pos * (destSX - sX);
|
153
|
+
sY = sY + pos * (destSY - sY);
|
154
|
+
}
|
155
|
+
getTransformImpl(outTransform, parentRect, childWidth, childHeight, focusX, focusY, sX, sY);
|
156
|
+
if (_imageMatrix != null) {
|
157
|
+
outTransform.preConcat(_imageMatrix);
|
158
|
+
} else if (_imageRotation != 0) {
|
159
|
+
outTransform.preRotate(_imageRotation, childWidth / 2.0f, childHeight / 2.0f);
|
160
|
+
}
|
161
|
+
|
162
|
+
return outTransform;
|
163
|
+
}
|
164
|
+
|
165
|
+
public abstract void getTransformImpl(
|
166
|
+
Matrix outTransform,
|
167
|
+
Rect parentRect,
|
168
|
+
int childWidth,
|
169
|
+
int childHeight,
|
170
|
+
float focusX,
|
171
|
+
float focusY,
|
172
|
+
float scaleX,
|
173
|
+
float scaleY);
|
174
|
+
}
|
175
|
+
|
176
|
+
private static class ScaleTypeFitXY extends AbstractScaleType {
|
177
|
+
|
178
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitXY();
|
179
|
+
|
180
|
+
@Override
|
181
|
+
public void getTransformImpl(
|
182
|
+
Matrix outTransform,
|
183
|
+
Rect parentRect,
|
184
|
+
int childWidth,
|
185
|
+
int childHeight,
|
186
|
+
float focusX,
|
187
|
+
float focusY,
|
188
|
+
float scaleX,
|
189
|
+
float scaleY) {
|
190
|
+
float dx = parentRect.left;
|
191
|
+
float dy = parentRect.top;
|
192
|
+
outTransform.setScale(scaleX, scaleY);
|
193
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
194
|
+
}
|
195
|
+
|
196
|
+
@Override
|
197
|
+
public String toString() {
|
198
|
+
return "fit_xy";
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
private static class ScaleTypeFitStart extends AbstractScaleType {
|
203
|
+
|
204
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitStart();
|
205
|
+
|
206
|
+
@Override
|
207
|
+
public void getTransformImpl(
|
208
|
+
Matrix outTransform,
|
209
|
+
Rect parentRect,
|
210
|
+
int childWidth,
|
211
|
+
int childHeight,
|
212
|
+
float focusX,
|
213
|
+
float focusY,
|
214
|
+
float scaleX,
|
215
|
+
float scaleY) {
|
216
|
+
float scale = Math.min(scaleX, scaleY);
|
217
|
+
float dx = parentRect.left;
|
218
|
+
float dy = parentRect.top;
|
219
|
+
outTransform.setScale(scale, scale);
|
220
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
221
|
+
}
|
222
|
+
|
223
|
+
@Override
|
224
|
+
public String toString() {
|
225
|
+
return "fit_start";
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
private static class ScaleTypeFitBottomStart extends AbstractScaleType {
|
230
|
+
|
231
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitBottomStart();
|
232
|
+
|
233
|
+
@Override
|
234
|
+
public void getTransformImpl(
|
235
|
+
Matrix outTransform,
|
236
|
+
Rect parentRect,
|
237
|
+
int childWidth,
|
238
|
+
int childHeight,
|
239
|
+
float focusX,
|
240
|
+
float focusY,
|
241
|
+
float scaleX,
|
242
|
+
float scaleY) {
|
243
|
+
float scale = Math.min(scaleX, scaleY);
|
244
|
+
float dx = parentRect.left;
|
245
|
+
float dy = parentRect.top + (parentRect.height() - childHeight * scale);
|
246
|
+
outTransform.setScale(scale, scale);
|
247
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
248
|
+
}
|
249
|
+
|
250
|
+
@Override
|
251
|
+
public String toString() {
|
252
|
+
return "fit_bottom_start";
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
private static class ScaleTypeFitCenter extends AbstractScaleType {
|
257
|
+
|
258
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitCenter();
|
259
|
+
|
260
|
+
@Override
|
261
|
+
public void getTransformImpl(
|
262
|
+
Matrix outTransform,
|
263
|
+
Rect parentRect,
|
264
|
+
int childWidth,
|
265
|
+
int childHeight,
|
266
|
+
float focusX,
|
267
|
+
float focusY,
|
268
|
+
float scaleX,
|
269
|
+
float scaleY) {
|
270
|
+
float scale = Math.min(scaleX, scaleY);
|
271
|
+
float dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
|
272
|
+
float dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
|
273
|
+
outTransform.setScale(scale, scale);
|
274
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
275
|
+
}
|
276
|
+
|
277
|
+
@Override
|
278
|
+
public String toString() {
|
279
|
+
return "fit_center";
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
private static class ScaleTypeFitEnd extends AbstractScaleType {
|
284
|
+
|
285
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitEnd();
|
286
|
+
|
287
|
+
@Override
|
288
|
+
public void getTransformImpl(
|
289
|
+
Matrix outTransform,
|
290
|
+
Rect parentRect,
|
291
|
+
int childWidth,
|
292
|
+
int childHeight,
|
293
|
+
float focusX,
|
294
|
+
float focusY,
|
295
|
+
float scaleX,
|
296
|
+
float scaleY) {
|
297
|
+
float scale = Math.min(scaleX, scaleY);
|
298
|
+
float dx = parentRect.left + (parentRect.width() - childWidth * scale);
|
299
|
+
float dy = parentRect.top + (parentRect.height() - childHeight * scale);
|
300
|
+
outTransform.setScale(scale, scale);
|
301
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
302
|
+
}
|
303
|
+
|
304
|
+
@Override
|
305
|
+
public String toString() {
|
306
|
+
return "fit_end";
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
private static class ScaleTypeCenter extends AbstractScaleType {
|
311
|
+
|
312
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeCenter();
|
313
|
+
|
314
|
+
@Override
|
315
|
+
public void getTransformImpl(
|
316
|
+
Matrix outTransform,
|
317
|
+
Rect parentRect,
|
318
|
+
int childWidth,
|
319
|
+
int childHeight,
|
320
|
+
float focusX,
|
321
|
+
float focusY,
|
322
|
+
float scaleX,
|
323
|
+
float scaleY) {
|
324
|
+
float dx = parentRect.left + (parentRect.width() - childWidth) * 0.5f;
|
325
|
+
float dy = parentRect.top + (parentRect.height() - childHeight) * 0.5f;
|
326
|
+
outTransform.setTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
327
|
+
}
|
328
|
+
|
329
|
+
@Override
|
330
|
+
public String toString() {
|
331
|
+
return "center";
|
332
|
+
}
|
333
|
+
}
|
334
|
+
|
335
|
+
private static class ScaleTypeCenterInside extends AbstractScaleType {
|
336
|
+
|
337
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeCenterInside();
|
338
|
+
|
339
|
+
@Override
|
340
|
+
public void getTransformImpl(
|
341
|
+
Matrix outTransform,
|
342
|
+
Rect parentRect,
|
343
|
+
int childWidth,
|
344
|
+
int childHeight,
|
345
|
+
float focusX,
|
346
|
+
float focusY,
|
347
|
+
float scaleX,
|
348
|
+
float scaleY) {
|
349
|
+
float scale = Math.min(Math.min(scaleX, scaleY), 1.0f);
|
350
|
+
float dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
|
351
|
+
float dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
|
352
|
+
outTransform.setScale(scale, scale);
|
353
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
354
|
+
}
|
355
|
+
|
356
|
+
@Override
|
357
|
+
public String toString() {
|
358
|
+
return "center_inside";
|
359
|
+
}
|
360
|
+
}
|
361
|
+
|
362
|
+
private static class ScaleTypeCenterCrop extends AbstractScaleType {
|
363
|
+
|
364
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeCenterCrop();
|
365
|
+
|
366
|
+
@Override
|
367
|
+
public void getTransformImpl(
|
368
|
+
Matrix outTransform,
|
369
|
+
Rect parentRect,
|
370
|
+
int childWidth,
|
371
|
+
int childHeight,
|
372
|
+
float focusX,
|
373
|
+
float focusY,
|
374
|
+
float scaleX,
|
375
|
+
float scaleY) {
|
376
|
+
float scale, dx, dy;
|
377
|
+
if (scaleY > scaleX) {
|
378
|
+
scale = scaleY;
|
379
|
+
dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
|
380
|
+
dy = parentRect.top;
|
381
|
+
} else {
|
382
|
+
scale = scaleX;
|
383
|
+
dx = parentRect.left;
|
384
|
+
dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
|
385
|
+
}
|
386
|
+
outTransform.setScale(scale, scale);
|
387
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
388
|
+
}
|
389
|
+
|
390
|
+
@Override
|
391
|
+
public String toString() {
|
392
|
+
return "center_crop";
|
393
|
+
}
|
394
|
+
}
|
395
|
+
|
396
|
+
private static class ScaleTypeFocusCrop extends AbstractScaleType {
|
397
|
+
|
398
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFocusCrop();
|
399
|
+
|
400
|
+
@Override
|
401
|
+
public void getTransformImpl(
|
402
|
+
Matrix outTransform,
|
403
|
+
Rect parentRect,
|
404
|
+
int childWidth,
|
405
|
+
int childHeight,
|
406
|
+
float focusX,
|
407
|
+
float focusY,
|
408
|
+
float scaleX,
|
409
|
+
float scaleY) {
|
410
|
+
float scale, dx, dy;
|
411
|
+
if (scaleY > scaleX) {
|
412
|
+
scale = scaleY;
|
413
|
+
dx = parentRect.width() * 0.5f - childWidth * scale * focusX;
|
414
|
+
dx = parentRect.left + Math.max(Math.min(dx, 0), parentRect.width() - childWidth * scale);
|
415
|
+
dy = parentRect.top;
|
416
|
+
} else {
|
417
|
+
scale = scaleX;
|
418
|
+
dx = parentRect.left;
|
419
|
+
dy = parentRect.height() * 0.5f - childHeight * scale * focusY;
|
420
|
+
dy = parentRect.top + Math.max(Math.min(dy, 0), parentRect.height() - childHeight * scale);
|
421
|
+
}
|
422
|
+
outTransform.setScale(scale, scale);
|
423
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
424
|
+
}
|
425
|
+
|
426
|
+
@Override
|
427
|
+
public String toString() {
|
428
|
+
return "focus_crop";
|
429
|
+
}
|
430
|
+
}
|
431
|
+
|
432
|
+
private static class ScaleTypeFitX extends AbstractScaleType {
|
433
|
+
|
434
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitX();
|
435
|
+
|
436
|
+
@Override
|
437
|
+
public void getTransformImpl(
|
438
|
+
Matrix outTransform,
|
439
|
+
Rect parentRect,
|
440
|
+
int childWidth,
|
441
|
+
int childHeight,
|
442
|
+
float focusX,
|
443
|
+
float focusY,
|
444
|
+
float scaleX,
|
445
|
+
float scaleY) {
|
446
|
+
float scale, dx, dy;
|
447
|
+
scale = scaleX;
|
448
|
+
dx = parentRect.left;
|
449
|
+
dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
|
450
|
+
outTransform.setScale(scale, scale);
|
451
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
452
|
+
}
|
453
|
+
|
454
|
+
@Override
|
455
|
+
public String toString() {
|
456
|
+
return "fit_x";
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
private static class ScaleTypeFitY extends AbstractScaleType {
|
461
|
+
|
462
|
+
public static final com.facebook.drawee.drawable.ScalingUtils.ScaleType INSTANCE = new ScaleTypeFitY();
|
463
|
+
|
464
|
+
@Override
|
465
|
+
public void getTransformImpl(
|
466
|
+
Matrix outTransform,
|
467
|
+
Rect parentRect,
|
468
|
+
int childWidth,
|
469
|
+
int childHeight,
|
470
|
+
float focusX,
|
471
|
+
float focusY,
|
472
|
+
float scaleX,
|
473
|
+
float scaleY) {
|
474
|
+
float scale, dx, dy;
|
475
|
+
scale = scaleY;
|
476
|
+
dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
|
477
|
+
dy = parentRect.top;
|
478
|
+
outTransform.setScale(scale, scale);
|
479
|
+
outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
|
480
|
+
}
|
481
|
+
|
482
|
+
@Override
|
483
|
+
public String toString() {
|
484
|
+
return "fit_y";
|
485
|
+
}
|
486
|
+
}
|
487
|
+
}
|
Binary file
|