@@ -52,7 +52,7 @@ public class GestureImageView extends ImageView {
5252 private boolean layout = false ;
5353
5454 private float scaleAdjust = 1.0f ;
55- private float startingScale = 1.0f ;
55+ private float startingScale = - 1.0f ;
5656
5757 private float scale = 1.0f ;
5858 private float maxScale = 5.0f ;
@@ -63,6 +63,8 @@ public class GestureImageView extends ImageView {
6363
6464 private float centerX ;
6565 private float centerY ;
66+
67+ private Float startX , startY ;
6668
6769 private int hWidth ;
6870 private int hHeight ;
@@ -99,18 +101,30 @@ public GestureImageView(Context context, AttributeSet attrs) {
99101 setScaleType (ScaleType .CENTER_INSIDE );
100102 }
101103
104+ String strStartX = attrs .getAttributeValue (LOCAL_NS , "start-x" );
105+ String strStartY = attrs .getAttributeValue (LOCAL_NS , "start-y" );
106+
107+ if (strStartX != null && strStartX .trim ().length () > 0 ) {
108+ startX = Float .parseFloat (strStartX );
109+ }
110+
111+ if (strStartY != null && strStartY .trim ().length () > 0 ) {
112+ startY = Float .parseFloat (strStartY );
113+ }
114+
115+ setStartingScale (attrs .getAttributeFloatValue (LOCAL_NS , "start-scale" , startingScale ));
102116 setMinScale (attrs .getAttributeFloatValue (LOCAL_NS , "min-scale" , minScale ));
103117 setMaxScale (attrs .getAttributeFloatValue (LOCAL_NS , "max-scale" , maxScale ));
104118 setStrict (attrs .getAttributeBooleanValue (LOCAL_NS , "strict" , strict ));
105119 setRecycle (attrs .getAttributeBooleanValue (LOCAL_NS , "recycle" , recycle ));
106120
107- initImage (false );
121+ initImage ();
108122 }
109123
110124 public GestureImageView (Context context ) {
111125 super (context );
112126 setScaleType (ScaleType .CENTER_INSIDE );
113- initImage (false );
127+ initImage ();
114128 }
115129
116130 @ Override
@@ -174,15 +188,29 @@ protected void setupCanvas(int measuredWidth, int measuredHeight, int orientatio
174188 measuredHeight -= (getPaddingTop () + getPaddingBottom ());
175189
176190 computeCropScale (imageWidth , imageHeight , measuredWidth , measuredHeight );
177- computeStartingScale (imageWidth , imageHeight , measuredWidth , measuredHeight );
191+
192+ if (startingScale <= 0.0f ) {
193+ computeStartingScale (imageWidth , imageHeight , measuredWidth , measuredHeight );
194+ }
178195
179196 scaleAdjust = startingScale ;
180197
181198 this .centerX = (float ) measuredWidth / 2.0f ;
182199 this .centerY = (float ) measuredHeight / 2.0f ;
200+
201+ if (startX == null ) {
202+ x = centerX ;
203+ }
204+ else {
205+ x = startX ;
206+ }
183207
184- x = centerX ;
185- y = centerY ;
208+ if (startY == null ) {
209+ y = centerY ;
210+ }
211+ else {
212+ y = startY ;
213+ }
186214
187215 gestureImageViewTouchListener = new GestureImageViewTouchListener (this , measuredWidth , measuredHeight );
188216
@@ -338,7 +366,7 @@ protected void onDetachedFromWindow() {
338366 super .onDetachedFromWindow ();
339367 }
340368
341- protected void initImage (boolean original ) {
369+ protected void initImage () {
342370 if (this .drawable != null ) {
343371 this .drawable .setAlpha (alpha );
344372 this .drawable .setFilterBitmap (true );
@@ -347,32 +375,24 @@ protected void initImage(boolean original) {
347375 }
348376 }
349377
350- if (!original ) {
351- layout = false ;
378+ if (!layout ) {
352379 requestLayout ();
353380 redraw ();
354381 }
355382 }
356383
357384 public void setImageBitmap (Bitmap image ) {
358- setImageBitmap (image , false );
359- }
360-
361- protected void setImageBitmap (Bitmap image , boolean original ) {
362385 this .drawable = new BitmapDrawable (getResources (), image );
363- initImage (original );
386+ initImage ();
364387 }
365388
366389 @ Override
367390 public void setImageDrawable (Drawable drawable ) {
368391 this .drawable = drawable ;
392+ initImage ();
369393 }
370394
371395 public void setImageResource (int id ) {
372- setImageResource (id , false );
373- }
374-
375- protected void setImageResource (int id , boolean original ) {
376396 if (this .drawable != null ) {
377397 this .recycle ();
378398 }
@@ -653,9 +673,16 @@ public boolean isLandscape() {
653673 public boolean isPortrait () {
654674 return getImageWidth () <= getImageHeight ();
655675 }
656-
657676
677+ public void setStartingScale (float startingScale ) {
678+ this .startingScale = startingScale ;
679+ }
658680
681+ public void setStartingPosition (float x , float y ) {
682+ this .startX = x ;
683+ this .startY = y ;
684+ }
685+
659686 @ Override
660687 public void setOnClickListener (OnClickListener l ) {
661688 this .onClickListener = l ;
0 commit comments