From 4b48227c9d8668dbb4bc0c72dcbfb35eb4c57ba3 Mon Sep 17 00:00:00 2001 From: t101d Date: Wed, 4 Mar 2015 21:40:32 +0800 Subject: Add display region. --- sample/res/layout/imagedisplay_region_fragment.xml | 73 ++++++++++++++++++++++ sample/res/layout/imagedisplay_rotate_fragment.xml | 1 - .../sample/imagedisplay/ImageDisplayActivity.java | 3 +- .../imagedisplay/ImageDisplayRegionFragment.java | 65 +++++++++++++++++++ .../imagedisplay/ImageDisplayRotateFragment.java | 6 ++ 5 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 sample/res/layout/imagedisplay_region_fragment.xml create mode 100644 sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayRegionFragment.java (limited to 'sample') diff --git a/sample/res/layout/imagedisplay_region_fragment.xml b/sample/res/layout/imagedisplay_region_fragment.xml new file mode 100644 index 0000000..b9367ba --- /dev/null +++ b/sample/res/layout/imagedisplay_region_fragment.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/res/layout/imagedisplay_rotate_fragment.xml b/sample/res/layout/imagedisplay_rotate_fragment.xml index 67e939b..f84524a 100644 --- a/sample/res/layout/imagedisplay_rotate_fragment.xml +++ b/sample/res/layout/imagedisplay_rotate_fragment.xml @@ -29,7 +29,6 @@ android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="@drawable/buttonstate_transparent" - android:visibility="invisible" android:paddingLeft="8dp" android:paddingRight="8dp" android:paddingTop="18dp" diff --git a/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayActivity.java b/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayActivity.java index a92d5d4..79142fd 100644 --- a/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayActivity.java +++ b/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayActivity.java @@ -47,7 +47,8 @@ public class ImageDisplayActivity extends FragmentActivity { } pages = Arrays.asList( new Page("Large images", ImageDisplayLargeFragment.class), - new Page("Rotation", ImageDisplayRotateFragment.class) + new Page("Rotation", ImageDisplayRotateFragment.class), + new Page("Display region", ImageDisplayRegionFragment.class) ); updatePage(); diff --git a/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayRegionFragment.java b/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayRegionFragment.java new file mode 100644 index 0000000..02f4b65 --- /dev/null +++ b/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayRegionFragment.java @@ -0,0 +1,65 @@ +/* +Copyright 2014 David Morrissey + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package com.davemorrissey.labs.subscaleview.sample.imagedisplay; + +import android.graphics.Rect; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; +import com.davemorrissey.labs.subscaleview.sample.R.id; +import com.davemorrissey.labs.subscaleview.sample.R.layout; + +import java.util.Random; + +public class ImageDisplayRegionFragment extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View rootView = inflater.inflate(layout.imagedisplay_region_fragment, container, false); + final SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(id.imageView); + imageView.setImageAsset("squirrel.jpg", null, randomRegion(2456, 1632)); + rootView.findViewById(id.previous).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + ((ImageDisplayActivity)getActivity()).previous(); + } + }); + rootView.findViewById(id.rotate).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + imageView.setOrientation((imageView.getOrientation() + 90) % 360); + } + }); + + return rootView; + } + + private static Rect randomRegion(int width, int height) { + Random random = new Random(System.nanoTime()); + + int left = random.nextInt(width - 2); + int top = random.nextInt(height - 2); + int right = random.nextInt(width - left + 1) + left; + int bottom = random.nextInt(height - top + 1) + top; + + return new Rect(left, top, right, bottom); + } +} diff --git a/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayRotateFragment.java b/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayRotateFragment.java index abe12a3..6088259 100644 --- a/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayRotateFragment.java +++ b/sample/src/com/davemorrissey/labs/subscaleview/sample/imagedisplay/ImageDisplayRotateFragment.java @@ -43,6 +43,12 @@ public class ImageDisplayRotateFragment extends Fragment { ((ImageDisplayActivity)getActivity()).previous(); } }); + rootView.findViewById(id.next).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + ((ImageDisplayActivity)getActivity()).next(); + } + }); rootView.findViewById(id.rotate).setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { -- cgit v1.2.3