From 58b6f484263f57009e22fef482a9ae1a4d3f48b6 Mon Sep 17 00:00:00 2001 From: Mangesh Ghiware Date: Mon, 7 Oct 2013 15:51:54 -0700 Subject: [PATCH] On K+, intent out to Wallpaper manager for crop and set wallpaper. Bug: 4225598 Change-Id: Ib58a85775ebfd774356d26fd9aa01f2059916300 --- src/com/android/gallery3d/app/Wallpaper.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/com/android/gallery3d/app/Wallpaper.java b/src/com/android/gallery3d/app/Wallpaper.java index b0a26c236..016a9ec09 100644 --- a/src/com/android/gallery3d/app/Wallpaper.java +++ b/src/com/android/gallery3d/app/Wallpaper.java @@ -18,6 +18,7 @@ package com.android.gallery3d.app; import android.annotation.TargetApi; import android.app.Activity; +import android.app.WallpaperManager; import android.content.Intent; import android.graphics.Point; import android.net.Uri; @@ -95,12 +96,18 @@ public class Wallpaper extends Activity { // fall-through } case STATE_PHOTO_PICKED: { - int width = getWallpaperDesiredMinimumWidth(); - int height = getWallpaperDesiredMinimumHeight(); - Point size = getDefaultDisplaySize(new Point()); - float spotlightX = (float) size.x / width; - float spotlightY = (float) size.y / height; - Intent request = new Intent(CropActivity.CROP_ACTION) + Intent cropAndSetWallpaperIntent; + if ("KeyLimePie".equals(Build.VERSION.CODENAME) + || Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + WallpaperManager wpm = WallpaperManager.getInstance(getApplicationContext()); + cropAndSetWallpaperIntent = wpm.getCropAndSetWallpaperIntent(mPickedItem); + } else { + int width = getWallpaperDesiredMinimumWidth(); + int height = getWallpaperDesiredMinimumHeight(); + Point size = getDefaultDisplaySize(new Point()); + float spotlightX = (float) size.x / width; + float spotlightY = (float) size.y / height; + cropAndSetWallpaperIntent = new Intent(CropActivity.CROP_ACTION) .setDataAndType(mPickedItem, IMAGE_TYPE) .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT) .putExtra(CropExtras.KEY_OUTPUT_X, width) @@ -112,7 +119,8 @@ public class Wallpaper extends Activity { .putExtra(CropExtras.KEY_SCALE, true) .putExtra(CropExtras.KEY_SCALE_UP_IF_NEEDED, true) .putExtra(CropExtras.KEY_SET_AS_WALLPAPER, true); - startActivity(request); + } + startActivity(cropAndSetWallpaperIntent); finish(); } } -- 2.11.0