diff options
-rw-r--r-- | res/drawable-nodpi/photo_039_002.jpg | bin | 314891 -> 618206 bytes | |||
-rw-r--r-- | res/layout/carousel.xml | 2 | ||||
-rw-r--r-- | res/values/config.xml | 3 | ||||
-rw-r--r-- | res/values/ids.xml | 1 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/dreams/phototable/FlipperDream.java | 2 | ||||
-rw-r--r-- | src/com/android/dreams/phototable/PhotoCarousel.java | 76 | ||||
-rw-r--r-- | src/com/android/dreams/phototable/PhotoSource.java | 12 | ||||
-rw-r--r-- | src/com/android/dreams/phototable/PicasaSource.java | 21 |
9 files changed, 88 insertions, 31 deletions
diff --git a/res/drawable-nodpi/photo_039_002.jpg b/res/drawable-nodpi/photo_039_002.jpg Binary files differindex f2fa084..3e14ef5 100644 --- a/res/drawable-nodpi/photo_039_002.jpg +++ b/res/drawable-nodpi/photo_039_002.jpg diff --git a/res/layout/carousel.xml b/res/layout/carousel.xml index bf7ce12..99ed269 100644 --- a/res/layout/carousel.xml +++ b/res/layout/carousel.xml @@ -30,7 +30,5 @@ android:layout_height="match_parent" android:scaleType="centerInside" android:alpha="0" - android:rotationY="180" /> </com.android.dreams.phototable.PhotoCarousel> - diff --git a/res/values/config.xml b/res/values/config.xml index 1305cf7..ea4cdb1 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -56,5 +56,8 @@ <!-- Maximum number of albums to pull for "Photos from Posts". --> <integer name="max_post_albums">100</integer> + <!-- Parts per million maximum cropping allow to fit image to screen. --> + <integer name="max_crop_ratio">1200000</integer> + </resources> diff --git a/res/values/ids.xml b/res/values/ids.xml index 4159edc..06dd088 100644 --- a/res/values/ids.xml +++ b/res/values/ids.xml @@ -17,5 +17,6 @@ <resources> <item type="id" name="photo_height" /> <item type="id" name="photo_width" /> + <item type="id" name="photo_orientation" /> <item type="id" name="data_payload" /> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 83de506..15cae95 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -16,7 +16,7 @@ <resources> <string name="app_name">Photo Screensavers</string> <string name="table_screensaver_name">Photo Table</string> - <string name="flipper_screensaver_name">Photo Flipper</string> + <string name="flipper_screensaver_name">Slideshow</string> <string name="posts_album_name">Photos from Posts</string> <string name="unknown_album_name">Unnamed Album</string> <string name="stock_photo_album_name">Stock Photos</string> 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(); } } |