am 0dca4fc9: am 55b523cc: Merge "[DO NOT MERGE] Fix wallpaper cropping bugs" into klp-dev

* commit '0dca4fc929638755454cc46a4eb21e86b3fcb0c8':
  [DO NOT MERGE] Fix wallpaper cropping bugs
This commit is contained in:
Adam Cohen
2014-03-19 20:24:02 +00:00
committed by Android Git Automerger
2 changed files with 34 additions and 5 deletions

View File

@ -165,7 +165,8 @@ public class CropView extends TiledImageView implements OnScaleGestureListener {
final float imageWidth = imageDims[0]; final float imageWidth = imageDims[0];
final float imageHeight = imageDims[1]; final float imageHeight = imageDims[1];
mMinScale = Math.max(w / imageWidth, h / imageHeight); mMinScale = Math.max(w / imageWidth, h / imageHeight);
mRenderer.scale = Math.max(mMinScale, mRenderer.scale); mRenderer.scale =
Math.max(mMinScale, resetScale ? Float.MIN_VALUE : mRenderer.scale);
} }
} }
} }

View File

@ -567,6 +567,8 @@ public class WallpaperCropActivity extends Activity {
Rect roundedTrueCrop = new Rect(); Rect roundedTrueCrop = new Rect();
Matrix rotateMatrix = new Matrix(); Matrix rotateMatrix = new Matrix();
Matrix inverseRotateMatrix = new Matrix(); Matrix inverseRotateMatrix = new Matrix();
Point bounds = getImageBounds();
if (mRotation > 0) { if (mRotation > 0) {
rotateMatrix.setRotate(mRotation); rotateMatrix.setRotate(mRotation);
inverseRotateMatrix.setRotate(-mRotation); inverseRotateMatrix.setRotate(-mRotation);
@ -574,7 +576,6 @@ public class WallpaperCropActivity extends Activity {
mCropBounds.roundOut(roundedTrueCrop); mCropBounds.roundOut(roundedTrueCrop);
mCropBounds = new RectF(roundedTrueCrop); mCropBounds = new RectF(roundedTrueCrop);
Point bounds = getImageBounds();
if (bounds == null) { if (bounds == null) {
Log.w(LOGTAG, "cannot get bounds for image"); Log.w(LOGTAG, "cannot get bounds for image");
failure = true; failure = true;
@ -646,12 +647,38 @@ public class WallpaperCropActivity extends Activity {
Utils.closeSilently(is); Utils.closeSilently(is);
} }
if (fullSize != null) { if (fullSize != null) {
// Find out the true sample size that was used by the decoder
scaleDownSampleSize = bounds.x / fullSize.getWidth();
mCropBounds.left /= scaleDownSampleSize; mCropBounds.left /= scaleDownSampleSize;
mCropBounds.top /= scaleDownSampleSize; mCropBounds.top /= scaleDownSampleSize;
mCropBounds.bottom /= scaleDownSampleSize; mCropBounds.bottom /= scaleDownSampleSize;
mCropBounds.right /= scaleDownSampleSize; mCropBounds.right /= scaleDownSampleSize;
mCropBounds.roundOut(roundedTrueCrop); mCropBounds.roundOut(roundedTrueCrop);
// Adjust values to account for issues related to rounding
if (roundedTrueCrop.width() > fullSize.getWidth()) {
// Adjust the width
roundedTrueCrop.right = roundedTrueCrop.left + fullSize.getWidth();
}
if (roundedTrueCrop.right > fullSize.getWidth()) {
// Adjust the left value
int adjustment = roundedTrueCrop.left -
Math.max(0, roundedTrueCrop.right - roundedTrueCrop.width());
roundedTrueCrop.left -= adjustment;
roundedTrueCrop.right -= adjustment;
}
if (roundedTrueCrop.height() > fullSize.getHeight()) {
// Adjust the height
roundedTrueCrop.bottom = roundedTrueCrop.top + fullSize.getHeight();
}
if (roundedTrueCrop.bottom > fullSize.getHeight()) {
// Adjust the top value
int adjustment = roundedTrueCrop.top -
Math.max(0, roundedTrueCrop.bottom - roundedTrueCrop.height());
roundedTrueCrop.top -= adjustment;
roundedTrueCrop.bottom -= adjustment;
}
crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left, crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left,
roundedTrueCrop.top, roundedTrueCrop.width(), roundedTrueCrop.top, roundedTrueCrop.width(),
roundedTrueCrop.height()); roundedTrueCrop.height());
@ -776,14 +803,15 @@ public class WallpaperCropActivity extends Activity {
final WallpaperManager wallpaperManager) { final WallpaperManager wallpaperManager) {
final Point defaultWallpaperSize = getDefaultWallpaperSize(res, windowManager); final Point defaultWallpaperSize = getDefaultWallpaperSize(res, windowManager);
new Thread("suggestWallpaperDimension") { new AsyncTask<Void, Void, Void>() {
public void run() { public Void doInBackground(Void ... args) {
// If we have saved a wallpaper width/height, use that instead // If we have saved a wallpaper width/height, use that instead
int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, defaultWallpaperSize.x); int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, defaultWallpaperSize.x);
int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, defaultWallpaperSize.y); int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, defaultWallpaperSize.y);
wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight); wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
return null;
} }
}.start(); }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
} }
protected static RectF getMaxCropRect( protected static RectF getMaxCropRect(