diff options
author | Chris Wren <cwren@android.com> | 2012-09-10 10:21:27 -0400 |
---|---|---|
committer | Chris Wren <cwren@android.com> | 2012-09-10 17:57:19 -0400 |
commit | 5b4b44688dac0053be77b282b7501bd291efb0d3 (patch) | |
tree | 151a81cc3f022946396c053339b409b3bd7d9c73 /src | |
parent | d85f53c69dead1f1f6c0290b8104422143bc5166 (diff) | |
download | android_packages_screensavers_PhotoTable-5b4b44688dac0053be77b282b7501bd291efb0d3.tar.gz android_packages_screensavers_PhotoTable-5b4b44688dac0053be77b282b7501bd291efb0d3.tar.bz2 android_packages_screensavers_PhotoTable-5b4b44688dac0053be77b282b7501bd291efb0d3.zip |
updated visuals for photo flipper
rename to "Slideshow"
no flipping
better photo scaling
bonus bug fix for PicasaSource
Bug: 7138425
Change-Id: I984b2d5b13716b676e55205f093df7bc929034c0
Diffstat (limited to 'src')
4 files changed, 83 insertions, 28 deletions
diff --git a/src/com/android/dreams/phototable/FlipperDream.java b/src/com/android/dreams/phototable/FlipperDream.java index f2e20b9..e4ec376 100644 --- a/src/com/android/dreams/phototable/FlipperDream.java +++ b/src/com/android/dreams/phototable/FlipperDream.java @@ -26,7 +26,7 @@ public class FlipperDream extends Dream { @Override public void onStart() { super.onStart(); - setInteractive(true); + setInteractive(false); } @Override diff --git a/src/com/android/dreams/phototable/PhotoCarousel.java b/src/com/android/dreams/phototable/PhotoCarousel.java index 99804d5..e1f41ba 100644 --- a/src/com/android/dreams/phototable/PhotoCarousel.java +++ b/src/com/android/dreams/phototable/PhotoCarousel.java @@ -37,6 +37,10 @@ import java.util.HashMap; */ public class PhotoCarousel extends FrameLayout { private static final String TAG = "PhotoCarousel"; + private static final boolean DEBUG = false; + + private static final int LANDSCAPE = 1; + private static final int PORTRAIT = 2; private final Flipper mFlipper; private final PhotoSourcePlexor mPhotoSource; @@ -46,6 +50,9 @@ public class PhotoCarousel extends FrameLayout { private final int mFlipDuration; private final int mDropPeriod; private boolean mOnce; + private int mOrientation; + private int mWidth; + private int mHeight; private int mLongSide; private int mShortSide; private final HashMap<View, Bitmap> mBitmapStore; @@ -74,7 +81,7 @@ public class PhotoCarousel extends FrameLayout { new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float vX, float vY) { - Log.i(TAG, "fling with " + vX); + log("fling with " + vX); flip(Math.signum(vX)); return true; } @@ -107,7 +114,16 @@ public class PhotoCarousel extends FrameLayout { public void onPostExecute(Bitmap photo) { if (photo != null) { Bitmap old = mBitmapStore.get(mDestination); + int width = PhotoCarousel.this.mOptions.outWidth; + int height = PhotoCarousel.this.mOptions.outHeight; + int orientation = (width > height ? LANDSCAPE : PORTRAIT); + mDestination.setImageBitmap(photo); + mDestination.setTag(R.id.photo_orientation, new Integer(orientation)); + mDestination.setTag(R.id.photo_width, new Integer(width)); + mDestination.setTag(R.id.photo_height, new Integer(height)); + PhotoCarousel.this.setScaleType(mDestination); + mBitmapStore.put(mDestination, photo); if (old != null) { old.recycle(); @@ -125,12 +141,35 @@ public class PhotoCarousel extends FrameLayout { } }; + private void setScaleType(View photo) { + if (photo.getTag(R.id.photo_orientation) != null) { + int orientation = ((Integer) photo.getTag(R.id.photo_orientation)).intValue(); + int width = ((Integer) photo.getTag(R.id.photo_width)).intValue(); + int height = ((Integer) photo.getTag(R.id.photo_height)).intValue(); + + if (width < mWidth && height < mHeight) { + log("too small: FIT_CENTER"); + ((ImageView) photo).setScaleType(ImageView.ScaleType.CENTER_CROP); + } else if (orientation == mOrientation) { + log("orientations match: CENTER_CROP"); + ((ImageView) photo).setScaleType(ImageView.ScaleType.CENTER_CROP); + } else { + log("orientations do not match: CENTER_INSIDE"); + ((ImageView) photo).setScaleType(ImageView.ScaleType.CENTER_INSIDE); + } + } else { + log("no tag!"); + } + } + public void flip(float sgn) { mPanel[0].animate().cancel(); mPanel[1].animate().cancel(); float frontY = mPanel[0].getRotationY(); float backY = mPanel[1].getRotationY(); + float frontA = mPanel[0].getAlpha(); + float backA = mPanel[1].getAlpha(); frontY = wrap360(frontY); backY = wrap360(backY); @@ -140,16 +179,11 @@ public class PhotoCarousel extends FrameLayout { frontY = lockTo180(frontY + sgn * 180f); backY = lockTo180(backY + sgn * 180f); + frontA = 1f - frontA; + backA = 1f - backA; - float frontA = 1f; - float backA = 0f; - if (frontY == 180f || frontY == -180f) { - frontA = 0f; - backA = 1f; - } else { - frontA = 1f; - backA = 0f; - } + // Don't rotate + frontY = backY = 0f; ViewPropertyAnimator frontAnim = mPanel[0].animate() .rotationY(frontY) @@ -184,12 +218,12 @@ public class PhotoCarousel extends FrameLayout { @Override public void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - int height = bottom - top; - int width = right - left; + mHeight = bottom - top; + mWidth = right - left; - mLongSide = (int) Math.max(width, height); - mShortSide = (int) Math.min(width, height); + mOrientation = (mWidth > mHeight ? LANDSCAPE : PORTRAIT); + mLongSide = (int) Math.max(mWidth, mHeight); + mShortSide = (int) Math.min(mWidth, mHeight); if (!mOnce) { mOnce = true; @@ -202,6 +236,12 @@ public class PhotoCarousel extends FrameLayout { scheduleNext(mDropPeriod); } + + // reset scale types for new aspect ratio + setScaleType(mPanel[0]); + setScaleType(mPanel[1]); + + super.onLayout(changed, left, top, right, bottom); } @Override @@ -214,4 +254,10 @@ public class PhotoCarousel extends FrameLayout { removeCallbacks(mFlipper); postDelayed(mFlipper, delay); } + + private void log(String message) { + if (DEBUG) { + Log.i(TAG, message); + } + } } diff --git a/src/com/android/dreams/phototable/PhotoSource.java b/src/com/android/dreams/phototable/PhotoSource.java index 32c7739..8a09bba 100644 --- a/src/com/android/dreams/phototable/PhotoSource.java +++ b/src/com/android/dreams/phototable/PhotoSource.java @@ -71,6 +71,7 @@ public abstract class PhotoSource { private final LinkedList<ImageData> mImageQueue; private final int mMaxQueueSize; + private final float mMaxCropRatio; protected final Context mContext; protected final Resources mResources; @@ -88,6 +89,7 @@ public abstract class PhotoSource { mResources = context.getResources(); mImageQueue = new LinkedList<ImageData>(); mMaxQueueSize = mResources.getInteger(R.integer.image_queue_size); + mMaxCropRatio = mResources.getInteger(R.integer.max_crop_ratio) / 1000000f; mRNG = new Random(); } @@ -122,8 +124,13 @@ public abstract class PhotoSource { log(TAG, "I see bounds of " + rawLongSide + ", " + rawShortSide); if (rawLongSide != -1 && rawShortSide != -1) { - float ratio = Math.max((float) longSide / (float) rawLongSide, - (float) shortSide / (float) rawShortSide); + float insideRatio = Math.max((float) longSide / (float) rawLongSide, + (float) shortSide / (float) rawShortSide); + float outsideRatio = Math.max((float) longSide / (float) rawLongSide, + (float) shortSide / (float) rawShortSide); + float ratio = (outsideRatio / insideRatio < mMaxCropRatio ? + outsideRatio : insideRatio); + while (ratio < 0.5) { options.inSampleSize *= 2; ratio *= 2; @@ -142,6 +149,7 @@ public abstract class PhotoSource { log(TAG, "still too big, scaling down by " + ratio); options.outWidth = (int) (ratio * options.outWidth); options.outHeight = (int) (ratio * options.outHeight); + image = Bitmap.createScaledBitmap(image, options.outWidth, options.outHeight, true); diff --git a/src/com/android/dreams/phototable/PicasaSource.java b/src/com/android/dreams/phototable/PicasaSource.java index 4d1c677..7f82cf9 100644 --- a/src/com/android/dreams/phototable/PicasaSource.java +++ b/src/com/android/dreams/phototable/PicasaSource.java @@ -80,12 +80,12 @@ public class PicasaSource extends PhotoSource { if (id.startsWith(TAG)) { String[] parts = id.split(":"); if (parts.length > 1) { - if (selection.length() > 0) { - selection.append(" OR "); - } if (PICASA_BUZZ_TYPE.equals(parts[1])) { usePosts = true; } else { + if (selection.length() > 0) { + selection.append(" OR "); + } log(TAG, "adding on: " + parts[1]); selection.append(PICASA_ALBUM_ID + " = '" + parts[1] + "'"); } @@ -223,9 +223,9 @@ public class PicasaSource extends PhotoSource { if (isBuzz) { id = TAG + ":" + PICASA_BUZZ_TYPE; } - - if (foundAlbums.get(id) == null) { - AlbumData data = new AlbumData(); + AlbumData data = foundAlbums.get(id); + if (data == null) { + data = new AlbumData(); data.id = id; if (isBuzz) { @@ -238,10 +238,6 @@ public class PicasaSource extends PhotoSource { mResources.getString(R.string.unknown_album_name, "Unknown"); } - if (updatedIndex >= 0) { - data.updated = cursor.getLong(updatedIndex); - } - if (thumbIndex >= 0) { data.thumbnailUrl = cursor.getString(thumbIndex); } @@ -250,6 +246,11 @@ public class PicasaSource extends PhotoSource { foundAlbums.put(id, data); } + if (updatedIndex >= 0) { + data.updated = (long) Math.max(data.updated, + cursor.getLong(updatedIndex)); + } + cursor.moveToNext(); } } |