diff options
author | James Kung <kingkung@google.com> | 2014-09-10 13:04:55 -0700 |
---|---|---|
committer | James Kung <kingkung@google.com> | 2014-09-10 13:54:48 -0700 |
commit | 3a79e2002f9f6114b549c4bc2cc08bb10e75a4d2 (patch) | |
tree | 6cb75e8bd2bb89134a95521784c4542da2c23c48 /src/com/android/bitmap/drawable | |
parent | d05e64cf9f9b1542ccdac8675c63b8b185c97a48 (diff) | |
download | bitmap-3a79e2002f9f6114b549c4bc2cc08bb10e75a4d2.tar.gz |
Allow user to choose horizontal crop alignment
Bug: 17272990
Change-Id: I8622d7e837dc1045a9b41c86dc91727bf152c8d3
Diffstat (limited to 'src/com/android/bitmap/drawable')
-rw-r--r-- | src/com/android/bitmap/drawable/BasicBitmapDrawable.java | 15 | ||||
-rw-r--r-- | src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java | 20 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java index d637a98..3ecc15b 100644 --- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java @@ -86,6 +86,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, private static final int MAX_BITMAP_DENSITY = DisplayMetrics.DENSITY_HIGH; private static final float VERTICAL_CENTER = 1f / 2; + private static final float HORIZONTAL_CENTER = 1f / 2; private static final float NO_MULTIPLIER = 1f; private static final String TAG = BasicBitmapDrawable.class.getSimpleName(); @@ -303,8 +304,8 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, if (mTask != null) { mTask.cancel(); } - final DecodeOptions opts = new DecodeOptions(bufferW, bufferH, getDecodeVerticalCenter(), - getDecodeStrategy()); + final DecodeOptions opts = new DecodeOptions(bufferW, bufferH, getDecodeHorizontalCenter(), + getDecodeVerticalCenter(), getDecodeStrategy()); mTask = new DecodeTask(mCurrKey, opts, factory, this, mCache); mTask.executeOnExecutor(getExecutor()); Trace.endSection(); @@ -333,6 +334,14 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, * Clients can override this to specify which section of the source image to decode from. * Possible applications include using face detection to always decode around facial features. */ + protected float getDecodeHorizontalCenter() { + return HORIZONTAL_CENTER; + } + + /** + * Clients can override this to specify which section of the source image to decode from. + * Possible applications include using face detection to always decode around facial features. + */ protected float getDecodeVerticalCenter() { return VERTICAL_CENTER; } @@ -348,7 +357,7 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback, BitmapUtils.calculateCroppedSrcRect( mBitmap.getLogicalWidth(), mBitmap.getLogicalHeight(), bounds.width(), bounds.height(), - bounds.height(), Integer.MAX_VALUE, + bounds.height(), Integer.MAX_VALUE, getDecodeHorizontalCenter(), getDrawVerticalCenter(), false /* absoluteFraction */, getDrawVerticalOffsetMultiplier(), sRect); diff --git a/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java b/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java index ab81e6f..fc54419 100644 --- a/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java +++ b/src/com/android/bitmap/drawable/ExtendedBitmapDrawable.java @@ -246,6 +246,11 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements } @Override + protected float getDecodeHorizontalCenter() { + return mOpts.decodeHorizontalCenter; + } + + @Override protected float getDecodeVerticalCenter() { return mOpts.decodeVerticalCenter; } @@ -690,6 +695,16 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements * Optional field for general decoding. * * This field determines which section of the source image to decode from. A value of 0 + * indicates a preference for the far left of the source, while a value of 1 indicates a + * preference for the far right of the source. A value of .5 will result in the center + * of the source being decoded. + */ + public float decodeHorizontalCenter = 1f / 2; + + /** + * Optional field for general decoding. + * + * This field determines which section of the source image to decode from. A value of 0 * indicates a preference for the very top of the source, while a value of 1 indicates a * preference for the very bottom of the source. A value of .5 will result in the center * of the source being decoded. @@ -778,6 +793,11 @@ public class ExtendedBitmapDrawable extends BasicBitmapDrawable implements */ private void validate() throws IllegalStateException { + if (decodeHorizontalCenter < 0 || decodeHorizontalCenter > 1) { + throw new IllegalStateException( + "ExtendedOptions: decodeHorizontalCenter must be within 0 and 1, " + + "inclusive"); + } if (decodeVerticalCenter < 0 || decodeVerticalCenter > 1) { throw new IllegalStateException( "ExtendedOptions: decodeVerticalCenter must be within 0 and 1, inclusive"); |