summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/WallpaperPickerActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/WallpaperPickerActivity.java')
-rw-r--r--src/com/android/launcher3/WallpaperPickerActivity.java78
1 files changed, 62 insertions, 16 deletions
diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java
index 5f35cde21..ef94fe86e 100644
--- a/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -29,11 +29,12 @@ import android.content.res.Resources;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
-import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LevelListDrawable;
import android.net.Uri;
@@ -58,6 +59,8 @@ import android.widget.ListAdapter;
import com.android.photos.BitmapRegionTileSource;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -87,11 +90,12 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
public static abstract class WallpaperTileInfo {
public void onClick(WallpaperPickerActivity a) {}
public void onSave(WallpaperPickerActivity a) {}
- public void onDelete() {}
+ public void onDelete(WallpaperPickerActivity a) {}
public boolean isSelectable() { return false; }
}
public static class PickImageInfo extends WallpaperTileInfo {
+ @Override
public void onClick(WallpaperPickerActivity a) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
@@ -104,13 +108,14 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
public UriWallpaperInfo(Uri uri) {
mUri = uri;
}
+ @Override
public void onClick(WallpaperPickerActivity a) {
CropView v = a.getCropView();
v.setTileSource(new BitmapRegionTileSource(
a, mUri, 1024, 0), null);
v.setTouchEnabled(true);
}
-
+ @Override
public void onSave(final WallpaperPickerActivity a) {
boolean finishActivityWhenDone = true;
OnBitmapCroppedHandler h = new OnBitmapCroppedHandler() {
@@ -123,6 +128,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
};
a.cropImageAndSetWallpaper(mUri, h, finishActivityWhenDone);
}
+ @Override
public boolean isSelectable() {
return true;
}
@@ -138,6 +144,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
mResId = resId;
mThumb = thumb;
}
+ @Override
public void onClick(WallpaperPickerActivity a) {
BitmapRegionTileSource source = new BitmapRegionTileSource(
mResources, a, mResId, 1024, 0);
@@ -151,10 +158,12 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
v.setScale(wallpaperSize.x / crop.width());
v.setTouchEnabled(false);
}
+ @Override
public void onSave(WallpaperPickerActivity a) {
boolean finishActivityWhenDone = true;
a.cropImageAndSetWallpaper(mResources, mResId, finishActivityWhenDone);
}
+ @Override
public boolean isSelectable() {
return true;
}
@@ -211,11 +220,11 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
return;
}
WallpaperTileInfo info = (WallpaperTileInfo) v.getTag();
- if (mSelectedThumb != null) {
- mSelectedThumb.setSelected(false);
- mSelectedThumb = null;
- }
if (info.isSelectable()) {
+ if (mSelectedThumb != null) {
+ mSelectedThumb.setSelected(false);
+ mSelectedThumb = null;
+ }
mSelectedThumb = v;
v.setSelected(true);
}
@@ -307,8 +316,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
new View.OnClickListener() {
@Override
public void onClick(View v) {
- WallpaperTileInfo info = (WallpaperTileInfo) mSelectedThumb.getTag();
- info.onSave(WallpaperPickerActivity.this);
+ if (mSelectedThumb != null) {
+ WallpaperTileInfo info = (WallpaperTileInfo) mSelectedThumb.getTag();
+ info.onSave(WallpaperPickerActivity.this);
+ }
}
});
@@ -361,7 +372,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
CheckableFrameLayout c =
(CheckableFrameLayout) mWallpapersView.getChildAt(i);
if (c.isChecked()) {
- ((WallpaperTileInfo) c.getTag()).onDelete();
+ WallpaperTileInfo info = (WallpaperTileInfo) c.getTag();
+ info.onDelete(WallpaperPickerActivity.this);
viewsToRemove.add(c);
}
}
@@ -462,7 +474,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
new BitmapCropTask(context, res, resId, null, width, height, false, true, null);
}
Point bounds = cropTask.getImageBounds();
- if (bounds == null) {
+ if (bounds == null || bounds.x == 0 || bounds.y == 0) {
return null;
}
@@ -546,14 +558,48 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
} catch (PackageManager.NameNotFoundException e) {
}
}
- //TODO: add default wallpaper
- //Resources sysRes = Resources.getSystem();
- //int resId = sysRes.getIdentifier("default_wallpaper", "drawable", "android");
- //bundledWallpapers.add(
- // new ResourceWallpaperInfo(sysRes, resId, new ColorDrawable(0xFFFF0000)));
+
+ // Add an entry for the default wallpaper (stored in system resources)
+ ResourceWallpaperInfo defaultWallpaperInfo = getDefaultWallpaperInfo();
+ if (defaultWallpaperInfo != null) {
+ bundledWallpapers.add(0, defaultWallpaperInfo);
+ }
return bundledWallpapers;
}
+ private ResourceWallpaperInfo getDefaultWallpaperInfo() {
+ Resources sysRes = Resources.getSystem();
+ int resId = sysRes.getIdentifier("default_wallpaper", "drawable", "android");
+
+ File defaultThumbFile = new File(getFilesDir(), "default_thumb.jpg");
+ Bitmap thumb = null;
+ boolean defaultWallpaperExists = false;
+ if (defaultThumbFile.exists()) {
+ thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath());
+ defaultWallpaperExists = true;
+ } else {
+ Point defaultThumbSize = getDefaultThumbnailSize(getResources());
+ thumb = createThumbnail(defaultThumbSize, this, null, null, sysRes, resId, false);
+ if (thumb != null) {
+ try {
+ defaultThumbFile.createNewFile();
+ FileOutputStream thumbFileStream =
+ openFileOutput(defaultThumbFile.getName(), Context.MODE_PRIVATE);
+ thumb.compress(Bitmap.CompressFormat.JPEG, 95, thumbFileStream);
+ thumbFileStream.close();
+ defaultWallpaperExists = true;
+ } catch (IOException e) {
+ Log.e(TAG, "Error while writing default wallpaper thumbnail to file " + e);
+ defaultThumbFile.delete();
+ }
+ }
+ }
+ if (defaultWallpaperExists) {
+ return new ResourceWallpaperInfo(sysRes, resId, new BitmapDrawable(thumb));
+ }
+ return null;
+ }
+
public Pair<ApplicationInfo, Integer> getWallpaperArrayResourceId() {
// Context.getPackageName() may return the "original" package name,
// com.android.launcher3; Resources needs the real package name,