1
1
package fr .nuage .souvenirs .model ;
2
2
3
+ import android .graphics .BitmapFactory ;
4
+
3
5
import androidx .lifecycle .MutableLiveData ;
4
6
5
7
import org .json .JSONException ;
@@ -12,11 +14,18 @@ public class ImageElement extends Element {
12
14
13
15
public static final int FIT = 0 ;
14
16
public static final int CENTERCROP = 1 ;
17
+ public static final int ZOOM_OFFSET = 2 ;
15
18
16
19
private MutableLiveData <String > ldImagePath = new MutableLiveData <String >();
17
20
private MutableLiveData <Integer > ldTransformType = new MutableLiveData <>();
21
+ private MutableLiveData <Integer > ldZoom = new MutableLiveData <>();
22
+ private MutableLiveData <Integer > ldOffsetX = new MutableLiveData <>();
23
+ private MutableLiveData <Integer > ldOffsetY = new MutableLiveData <>();
18
24
private String imagePath ;
19
25
private String mimeType ;
26
+ private int zoom = 100 ;
27
+ private int offsetX = 0 ;
28
+ private int offsetY = 0 ;
20
29
private int transformType = FIT ;
21
30
22
31
public ImageElement () {
@@ -103,6 +112,9 @@ public JSONObject completeToJSON(JSONObject json) throws JSONException {
103
112
json .put ("image" ,Utils .getRelativePath (pageParent .getAlbum ().getAlbumPath (),imagePath ));
104
113
json .put ("mime" ,mimeType );
105
114
json .put ("transformType" ,transformType );
115
+ json .put ("zoom" ,zoom );
116
+ json .put ("offsetX" ,offsetX );
117
+ json .put ("offsetY" ,offsetY );
106
118
return json ;
107
119
}
108
120
@@ -122,6 +134,15 @@ public void completeFromJSON(JSONObject jsonObject) throws JSONException {
122
134
if (jsonObject .has ("transformType" )) {
123
135
setTransformType (jsonObject .getInt ("transformType" ),false );
124
136
}
137
+ if (jsonObject .has ("zoom" )) {
138
+ setZoom (jsonObject .getInt ("zoom" ),false );
139
+ }
140
+ if (jsonObject .has ("offsetX" )) {
141
+ setOffsetX (jsonObject .getInt ("offsetX" ),false );
142
+ }
143
+ if (jsonObject .has ("offsetY" )) {
144
+ setOffsetY (jsonObject .getInt ("offsetY" ),false );
145
+ }
125
146
}
126
147
127
148
public String getImagePath () {
@@ -163,4 +184,84 @@ public void delete() {
163
184
public void setAsAlbumImage () {
164
185
pageParent .getAlbum ().setAlbumImage (getImagePath ());
165
186
}
187
+
188
+ public int getZoom () {
189
+ return zoom ;
190
+ }
191
+
192
+ public void setZoom (int zoom ) {
193
+ setZoom (zoom ,true );
194
+ }
195
+
196
+ public void setZoom (int zoom , boolean save ) {
197
+ this .zoom = zoom ;
198
+ ldZoom .postValue (zoom );
199
+ if (save ) {
200
+ onChange ();
201
+ }
202
+ }
203
+
204
+ public int getOffsetX () {
205
+ return offsetX ;
206
+ }
207
+
208
+ public void setOffsetX (int offsetX ) {
209
+ setOffsetX (offsetX ,true );
210
+ }
211
+
212
+ public void setOffsetX (int offsetX , boolean save ) {
213
+ this .offsetX = offsetX ;
214
+ ldOffsetX .postValue (offsetX );
215
+ if (save ) {
216
+ onChange ();
217
+ }
218
+ }
219
+
220
+ public int getOffsetY () {
221
+ return offsetY ;
222
+ }
223
+
224
+ public void setOffsetY (int offsetY ) {
225
+ setOffsetY (offsetY ,true );
226
+ }
227
+
228
+ public void setOffsetY (int offsetY , boolean save ) {
229
+ this .offsetY = offsetY ;
230
+ ldOffsetY .postValue (offsetY );
231
+ if (save ) {
232
+ onChange ();
233
+ }
234
+ }
235
+
236
+ public MutableLiveData <Integer > getLdZoom () {
237
+ return ldZoom ;
238
+ }
239
+
240
+ public MutableLiveData <Integer > getLdOffsetX () {
241
+ return ldOffsetX ;
242
+ }
243
+
244
+ public MutableLiveData <Integer > getLdOffsetY () {
245
+ return ldOffsetY ;
246
+ }
247
+
248
+ public int getImageWidth () {
249
+ if ((imagePath == null ) || (imagePath .equals ("" ))) {
250
+ return 0 ;
251
+ }
252
+ BitmapFactory .Options options = new BitmapFactory .Options ();
253
+ options .inJustDecodeBounds = true ;
254
+ BitmapFactory .decodeFile (imagePath , options );
255
+ return options .outWidth ;
256
+ }
257
+
258
+ public int getImageHeight () {
259
+ if ((imagePath == null ) || (imagePath .equals ("" ))) {
260
+ return 0 ;
261
+ }
262
+ BitmapFactory .Options options = new BitmapFactory .Options ();
263
+ options .inJustDecodeBounds = true ;
264
+ BitmapFactory .decodeFile (imagePath , options );
265
+ return options .outHeight ;
266
+ }
166
267
}
0 commit comments