diff options
Diffstat (limited to 'WallpaperPicker')
3 files changed, 31 insertions, 6 deletions
diff --git a/WallpaperPicker/res/values/config.xml b/WallpaperPicker/res/values/config.xml index 1b2419073..71580b5b0 100644 --- a/WallpaperPicker/res/values/config.xml +++ b/WallpaperPicker/res/values/config.xml @@ -15,4 +15,7 @@ --> <resources> <bool name="allow_rotation">false</bool> + <!-- Specifies whether to expand the cropped area on both sides (rather + than just to one side) --> + <bool name="center_crop">false</bool> </resources> diff --git a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java index 58add7022..44bfdf1f9 100644 --- a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java +++ b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java @@ -85,6 +85,9 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter { } public SavedWallpaperImages(Activity context) { + // We used to store the saved images in the cache directory, but that meant they'd get + // deleted sometimes-- move them to the data directory + ImageDb.moveFromCacheDirectoryIfNecessary(context); mDb = new ImageDb(context); mContext = context; mLayoutInflater = context.getLayoutInflater(); @@ -215,11 +218,20 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter { Context mContext; public ImageDb(Context context) { - super(context, new File(context.getCacheDir(), DB_NAME).getPath(), null, DB_VERSION); + super(context, context.getDatabasePath(DB_NAME).getPath(), null, DB_VERSION); // Store the context for later use mContext = context; } + public static void moveFromCacheDirectoryIfNecessary(Context context) { + // We used to store the saved images in the cache directory, but that meant they'd get + // deleted sometimes-- move them to the data directory + File oldSavedImagesFile = new File(context.getCacheDir(), ImageDb.DB_NAME); + File savedImagesFile = context.getDatabasePath(ImageDb.DB_NAME); + if (oldSavedImagesFile.exists()) { + oldSavedImagesFile.renameTo(savedImagesFile); + } + } @Override public void onCreate(SQLiteDatabase database) { database.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" + diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java index b3ef07309..ee7b81951 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java @@ -330,10 +330,10 @@ public class WallpaperCropActivity extends Activity { protected void cropImageAndSetWallpaper(Uri uri, OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone) { + boolean centerCrop = getResources().getBoolean(R.bool.center_crop); // Get the crop boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR; - Display d = getWindowManager().getDefaultDisplay(); Point displaySize = new Point(); @@ -358,15 +358,25 @@ public class WallpaperCropActivity extends Activity { // ADJUST CROP WIDTH // Extend the crop all the way to the right, for parallax // (or all the way to the left, in RTL) - float extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left; + float extraSpace; + if (centerCrop) { + extraSpace = 2f * Math.min(rotatedInSize[0] - cropRect.right, cropRect.left); + } else { + extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left; + } // Cap the amount of extra width float maxExtraSpace = defaultWallpaperSize.x / cropScale - cropRect.width(); extraSpace = Math.min(extraSpace, maxExtraSpace); - if (ltr) { - cropRect.right += extraSpace; + if (centerCrop) { + cropRect.left -= extraSpace / 2f; + cropRect.right += extraSpace / 2f; } else { - cropRect.left -= extraSpace; + if (ltr) { + cropRect.right += extraSpace; + } else { + cropRect.left -= extraSpace; + } } // ADJUST CROP HEIGHT |