diff options
author | David Morrissey <davemorrissey@gmail.com> | 2014-06-07 23:53:01 +0100 |
---|---|---|
committer | David Morrissey <davemorrissey@gmail.com> | 2014-06-07 23:53:01 +0100 |
commit | 7a269be94d4126a0e43fc40dd70defd0a8dfe94f (patch) | |
tree | e93842d510736cf7025035f49790bb78857230b1 | |
parent | ae23e81fd93c60ea96c2c4835567e404b29afc6a (diff) | |
download | subsampling-scale-image-view-7a269be94d4126a0e43fc40dd70defd0a8dfe94f.tar.gz |
Reset method
3 files changed, 22 insertions, 0 deletions
diff --git a/library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java b/library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java index 894d103..7a2afb3 100644 --- a/library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java +++ b/library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java @@ -1419,6 +1419,16 @@ public class SubsamplingScaleImageView extends View { } /** + * Fully zoom out and return the image to the middle of the screen. This might be useful if you have a view pager + * and want images to be reset when the user has moved to another page. + */ + public final void resetScaleAndCenter() { + this.pendingScale = limitedScale(0); + this.sPendingCenter = new PointF(0, 0); + invalidate(); + } + + /** * Subclasses can override this method to be informed when the view is set up and ready for rendering, so they can * skip their own rendering until the base layer (and its scale and translate) are known. */ diff --git a/sample/res/layout/page.xml b/sample/res/layout/page.xml index 3c058dd..564bfac 100644 --- a/sample/res/layout/page.xml +++ b/sample/res/layout/page.xml @@ -34,4 +34,12 @@ android:layout_height="wrap_content" android:layout_margin="5dp"/> + <Button android:id="@+id/reset" + android:text="Reset" + android:layout_toLeftOf="@id/center" + android:layout_alignParentBottom="true" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="5dp"/> + </RelativeLayout>
\ No newline at end of file diff --git a/sample/src/com/davemorrissey/labs/subscaleview/sample/PageFragment.java b/sample/src/com/davemorrissey/labs/subscaleview/sample/PageFragment.java index accf582..db51994 100644 --- a/sample/src/com/davemorrissey/labs/subscaleview/sample/PageFragment.java +++ b/sample/src/com/davemorrissey/labs/subscaleview/sample/PageFragment.java @@ -65,6 +65,7 @@ public class PageFragment extends Fragment implements OnClickListener, OnLongCli rootView.findViewById(id.rotate).setOnClickListener(this); rootView.findViewById(id.scale).setOnClickListener(this); rootView.findViewById(id.center).setOnClickListener(this); + rootView.findViewById(id.reset).setOnClickListener(this); if (asset != null) { SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(id.imageView); imageView.setImageAsset(asset, imageViewState); @@ -100,6 +101,9 @@ public class PageFragment extends Fragment implements OnClickListener, OnLongCli int sy = random.nextInt(imageView.getSHeight()); imageView.animateCenter(new PointF(sx, sy)).withDuration(1500).start(); } + } else if (view.getId() == id.reset && rootView != null) { + SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(id.imageView); + imageView.resetScaleAndCenter(); } else if (view.getId() == id.imageView) { Toast.makeText(getActivity(), "Clicked", Toast.LENGTH_SHORT).show(); } |