summaryrefslogtreecommitdiffstats
path: root/photoviewer
diff options
context:
space:
mode:
authorAdam Copp <adamcopp@google.com>2012-09-04 15:09:20 +0100
committerAdam Copp <adamcopp@google.com>2012-09-04 15:15:28 +0100
commitb4206edfa1df21bd6a415f49561c65539b37497c (patch)
tree6ec28040e84295f6e3cf6388fccbd0632c32aa73 /photoviewer
parent893e4c3c716679f142a5d64efb987fb8b833cd25 (diff)
downloadandroid_frameworks_ex-b4206edfa1df21bd6a415f49561c65539b37497c.tar.gz
android_frameworks_ex-b4206edfa1df21bd6a415f49561c65539b37497c.tar.bz2
android_frameworks_ex-b4206edfa1df21bd6a415f49561c65539b37497c.zip
Add parameter for max initial scale factor
you can now pass EXTRA_MAX_INITIAL_SCALE into PhotoViewActivity in order to specify the maximum initial scale of images displayed. This parameter defaults to 1x if now supplied, so images will not be displayed larger than their actual size by default. This allows the gmail team to resolve 7049410 whilst velvet can keep something like the old behaviour (which is more natural for their app) Bug: 7049410 Change-Id: I7d230666ca50a4634d8436519ed280cc6e558ee3
Diffstat (limited to 'photoviewer')
-rw-r--r--photoviewer/src/com/android/ex/photo/Intents.java15
-rw-r--r--photoviewer/src/com/android/ex/photo/PhotoViewActivity.java8
-rw-r--r--photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java7
-rw-r--r--photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java1
-rw-r--r--photoviewer/src/com/android/ex/photo/views/PhotoView.java16
5 files changed, 41 insertions, 6 deletions
diff --git a/photoviewer/src/com/android/ex/photo/Intents.java b/photoviewer/src/com/android/ex/photo/Intents.java
index 0e64730..e1e77d3 100644
--- a/photoviewer/src/com/android/ex/photo/Intents.java
+++ b/photoviewer/src/com/android/ex/photo/Intents.java
@@ -34,6 +34,7 @@ public class Intents {
public static final String EXTRA_RESOLVED_PHOTO_URI = "resolved_photo_uri";
public static final String EXTRA_PROJECTION = "projection";
public static final String EXTRA_THUMBNAIL_URI = "thumbnail_uri";
+ public static final String EXTRA_MAX_INITIAL_SCALE = "max_scale";
/**
* Gets a photo view intent builder to display the photos from phone activity.
@@ -75,6 +76,8 @@ public class Intents {
private String[] mProjection;
/** The URI of a thumbnail of the photo to display */
private String mThumbnailUri;
+ /** The maximum scale to display images at before */
+ private Float mMaxInitialScale;
private PhotoViewIntentBuilder(Context context, Class<?> cls) {
mIntent = new Intent(context, cls);
@@ -116,6 +119,14 @@ public class Intents {
return this;
}
+ /**
+ * Sets the maximum scale which an image is initially displayed at
+ */
+ public PhotoViewIntentBuilder setMaxInitialScale(float maxScale) {
+ mMaxInitialScale = maxScale;
+ return this;
+ }
+
/** Build the intent */
public Intent build() {
mIntent.setAction(Intent.ACTION_VIEW);
@@ -142,6 +153,10 @@ public class Intents {
mIntent.putExtra(EXTRA_THUMBNAIL_URI, mThumbnailUri);
}
+ if (mMaxInitialScale != null) {
+ mIntent.putExtra(EXTRA_MAX_INITIAL_SCALE, mMaxInitialScale);
+ }
+
return mIntent;
}
}
diff --git a/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java b/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java
index f783420..8628331 100644
--- a/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java
+++ b/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java
@@ -134,6 +134,8 @@ public class PhotoViewActivity extends Activity implements
private boolean mRestartLoader;
/** Whether or not this activity is paused */
private boolean mIsPaused = true;
+ /** The maximum scale factor applied to images when they are initially displayed */
+ private float mMaxInitialScale;
private final Handler mHandler = new Handler();
// TODO Find a better way to do this. We basically want the activity to display the
// "loading..." progress until the fragment takes over and shows it's own "loading..."
@@ -177,12 +179,16 @@ public class PhotoViewActivity extends Activity implements
if (mIntent.hasExtra(Intents.EXTRA_PHOTO_INDEX) && currentItem < 0) {
currentItem = mIntent.getIntExtra(Intents.EXTRA_PHOTO_INDEX, -1);
}
+
+ // Set the max initial scale, defaulting to 1x
+ mMaxInitialScale = mIntent.getFloatExtra(Intents.EXTRA_MAX_INITIAL_SCALE, 1.0f);
+
mPhotoIndex = currentItem;
setContentView(R.layout.photo_activity_view);
// Create the adapter and add the view pager
- mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null);
+ mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null, mMaxInitialScale);
mViewPager = (PhotoViewPager) findViewById(R.id.photo_view_pager);
mViewPager.setAdapter(mAdapter);
diff --git a/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java b/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
index bf75ecb..d22a378 100644
--- a/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
+++ b/photoviewer/src/com/android/ex/photo/adapters/PhotoPagerAdapter.java
@@ -33,9 +33,11 @@ import com.android.ex.photo.provider.PhotoContract;
public class PhotoPagerAdapter extends BaseCursorPagerAdapter {
private int mContentUriIndex;
private int mThumbnailUriIndex;
+ private float mMaxScale;
- public PhotoPagerAdapter(Context context, FragmentManager fm, Cursor c) {
+ public PhotoPagerAdapter(Context context, FragmentManager fm, Cursor c, float maxScale) {
super(context, fm, c);
+ mMaxScale = maxScale;
}
@Override
@@ -48,7 +50,8 @@ public class PhotoPagerAdapter extends BaseCursorPagerAdapter {
Intents.newPhotoViewFragmentIntentBuilder(mContext);
builder
.setResolvedPhotoUri(photoUri)
- .setThumbnailUri(thumbnailUri);
+ .setThumbnailUri(thumbnailUri)
+ .setMaxInitialScale(mMaxScale);
return new PhotoViewFragment(builder.build(), position, this);
}
diff --git a/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java b/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java
index 4da6ab0..7be37b0 100644
--- a/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java
+++ b/photoviewer/src/com/android/ex/photo/fragments/PhotoViewFragment.java
@@ -179,6 +179,7 @@ public class PhotoViewFragment extends Fragment implements
final View view = inflater.inflate(R.layout.photo_fragment_view, container, false);
mPhotoView = (PhotoView) view.findViewById(R.id.photo_view);
+ mPhotoView.setMaxInitialScale(mIntent.getFloatExtra(Intents.EXTRA_MAX_INITIAL_SCALE, 1));
mPhotoView.setOnClickListener(this);
mPhotoView.setFullScreen(mFullScreen, false);
mPhotoView.enableImageTransforms(true);
diff --git a/photoviewer/src/com/android/ex/photo/views/PhotoView.java b/photoviewer/src/com/android/ex/photo/views/PhotoView.java
index e767cba..c815b8a 100644
--- a/photoviewer/src/com/android/ex/photo/views/PhotoView.java
+++ b/photoviewer/src/com/android/ex/photo/views/PhotoView.java
@@ -106,6 +106,8 @@ public class PhotoView extends View implements GestureDetector.OnGestureListener
private Rect mCropRect = new Rect();
/** Actual crop size; may differ from {@link #sCropSize} if the screen is smaller */
private int mCropSize;
+ /** The maximum amount of scaling to apply to images */
+ private float mMaxInitialScaleFactor;
/** Gesture detector */
private GestureDetector mGestureDetector;
@@ -709,9 +711,13 @@ public class PhotoView extends View implements GestureDetector.OnGestureListener
} else {
mTempDst.set(0, 0, vwidth, vheight);
}
-
- if (dwidth < vwidth && dheight < vheight && !mAllowCrop) {
- mMatrix.setTranslate(vwidth / 2 - dwidth / 2, vheight / 2 - dheight / 2);
+ RectF scaledDestination = new RectF(
+ (vwidth / 2) - (dwidth * mMaxInitialScaleFactor / 2),
+ (vheight / 2) - (dheight * mMaxInitialScaleFactor / 2),
+ (vwidth / 2) + (dwidth * mMaxInitialScaleFactor / 2),
+ (vheight / 2) + (dheight * mMaxInitialScaleFactor / 2));
+ if(mTempDst.contains(scaledDestination)) {
+ mMatrix.setRectToRect(mTempSrc, scaledDestination, Matrix.ScaleToFit.CENTER);
} else {
mMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER);
}
@@ -1298,4 +1304,8 @@ public class PhotoView extends View implements GestureDetector.OnGestureListener
mHeader.post(this);
}
}
+
+ public void setMaxInitialScale(float f) {
+ mMaxInitialScaleFactor = f;
+ }
}