Update to use new wallpaper APIs.
diff --git a/src/com/android/launcher2/WallpaperChooser.java b/src/com/android/launcher2/WallpaperChooser.java
index 02e85ee..4517bf5 100644
--- a/src/com/android/launcher2/WallpaperChooser.java
+++ b/src/com/android/launcher2/WallpaperChooser.java
@@ -17,15 +17,12 @@
package com.android.launcher2;
import android.app.Activity;
-import android.app.IWallpaperService;
+import android.app.WallpaperManager;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
-import android.os.ParcelFileDescriptor;
-import android.os.RemoteException;
-import android.os.ServiceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -39,8 +36,6 @@
import android.widget.ImageView;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Collections;
@@ -90,7 +85,6 @@
private ArrayList<Integer> mThumbs;
private ArrayList<Integer> mImages;
- private ArrayList<String> mNames;
@Override
public void onCreate(Bundle icicle) {
@@ -125,11 +119,6 @@
final Resources resources = getResources();
- mNames = new ArrayList<String>(IMAGE_IDS.length + 4);
- for (int res: mImages) {
- mNames.add("res:" + resources.getResourceName(res));
- }
-
final String[] extras = resources.getStringArray(R.array.extra_wallpapers);
final String packageName = getApplication().getPackageName();
@@ -142,7 +131,6 @@
if (thumbRes != 0) {
mThumbs.add(thumbRes);
mImages.add(res);
- mNames.add("res:" + extra);
}
}
}
@@ -182,8 +170,9 @@
mIsWallpaperSet = true;
try {
- InputStream stream = getResources().openRawResource(mImages.get(position));
- setWallpaper(stream, mNames.get(position));
+ WallpaperManager wpm = (WallpaperManager)getSystemService(
+ WALLPAPER_SERVICE);
+ wpm.set(mImages.get(position));
setResult(RESULT_OK);
finish();
} catch (IOException e) {
@@ -231,34 +220,4 @@
public void onClick(View v) {
selectWallpaper(mGallery.getSelectedItemPosition());
}
-
- private void setWallpaper(InputStream data, String name) throws IOException {
- try {
- IWallpaperService svc = IWallpaperService.Stub.asInterface(
- ServiceManager.getService(WALLPAPER_SERVICE));
- ParcelFileDescriptor fd = svc.setWallpaper(name);
- if (fd == null) {
- return;
- }
- FileOutputStream fos = null;
- try {
- fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
- setWallpaper(data, fos);
- } finally {
- if (fos != null) {
- fos.close();
- }
- }
- } catch (RemoteException e) {
- }
- }
-
- private void setWallpaper(InputStream data, FileOutputStream fos)
- throws IOException {
- byte[] buffer = new byte[32768];
- int amt;
- while ((amt=data.read(buffer)) > 0) {
- fos.write(buffer, 0, amt);
- }
- }
}