diff options
Diffstat (limited to 'packages/WallpaperCropper/src/com')
-rw-r--r-- | packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java b/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java index 98faa88..d6c0c99 100644 --- a/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java +++ b/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java @@ -75,6 +75,7 @@ public class WallpaperCropActivity extends Activity { protected CropView mCropView; protected Uri mUri; + private View mSetWallpaperButton; @Override protected void onCreate(Bundle savedInstanceState) { @@ -111,10 +112,12 @@ public class WallpaperCropActivity extends Activity { cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone); } }); + mSetWallpaperButton = findViewById(R.id.set_wallpaper_button); // Load image in background final BitmapRegionTileSource.UriBitmapSource bitmapSource = new BitmapRegionTileSource.UriBitmapSource(this, imageUri, 1024); + mSetWallpaperButton.setVisibility(View.INVISIBLE); Runnable onLoad = new Runnable() { public void run() { if (bitmapSource.getLoadingState() != BitmapSource.State.LOADED) { @@ -122,6 +125,8 @@ public class WallpaperCropActivity extends Activity { getString(R.string.wallpaper_load_fail), Toast.LENGTH_LONG).show(); finish(); + } else { + mSetWallpaperButton.setVisibility(View.VISIBLE); } } }; @@ -136,7 +141,21 @@ public class WallpaperCropActivity extends Activity { final AsyncTask<Void, Void, Void> loadBitmapTask = new AsyncTask<Void, Void, Void>() { protected Void doInBackground(Void...args) { if (!isCancelled()) { - bitmapSource.loadInBackground(); + try { + bitmapSource.loadInBackground(); + } catch (SecurityException securityException) { + if (isDestroyed()) { + // Temporarily granted permissions are revoked when the activity + // finishes, potentially resulting in a SecurityException here. + // Even though {@link #isDestroyed} might also return true in different + // situations where the configuration changes, we are fine with + // catching these cases here as well. + cancel(false); + } else { + // otherwise it had a different cause and we throw it further + throw securityException; + } + } } return null; } @@ -343,6 +362,13 @@ public class WallpaperCropActivity extends Activity { getWindowManager()); // Get the crop RectF cropRect = mCropView.getCrop(); + + // Due to rounding errors in the cropview renderer the edges can be slightly offset + // therefore we ensure that the boundaries are sanely defined + cropRect.left = Math.max(0, cropRect.left); + cropRect.right = Math.min(mCropView.getWidth(), cropRect.right); + cropRect.top = Math.max(0, cropRect.top); + cropRect.bottom = Math.min(mCropView.getHeight(), cropRect.bottom); int cropRotation = mCropView.getImageRotation(); float cropScale = mCropView.getWidth() / (float) cropRect.width(); |