diff options
Diffstat (limited to 'WallpaperPicker')
6 files changed, 207 insertions, 125 deletions
diff --git a/WallpaperPicker/res/drawable-xxhdpi/ic_actionbar_accept.png b/WallpaperPicker/res/drawable-xxhdpi/ic_actionbar_accept.png Binary files differnew file mode 100755 index 000000000..d9ad51c9b --- /dev/null +++ b/WallpaperPicker/res/drawable-xxhdpi/ic_actionbar_accept.png diff --git a/WallpaperPicker/res/values-am/strings.xml b/WallpaperPicker/res/values-am/strings.xml index 394161634..59c3bf733 100644 --- a/WallpaperPicker/res/values-am/strings.xml +++ b/WallpaperPicker/res/values-am/strings.xml @@ -19,7 +19,7 @@ <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> - <string name="wallpaper_instructions" msgid="3524143401182707094">"የግድግዳ ወረቀት አዘጋጅ"</string> + <string name="wallpaper_instructions" msgid="3524143401182707094">"ልጣፍ አዘጋጅ"</string> <string name="image_load_fail" msgid="7538534580694411837">"ምስሉን መጫን አልተቻለም"</string> <string name="wallpaper_load_fail" msgid="4800700444605404650">"ምስሉን እንደ ግድግዳ ወረቀት መጫን አልተቻለም"</string> <plurals name="number_of_items_selected"> @@ -27,10 +27,10 @@ <item quantity="one" msgid="8409622005831789373">"%1$d ተመርጧል"</item> <item quantity="other" msgid="479468347731745357">"%1$d ተመርጧል"</item> </plurals> - <string name="wallpaper_accessibility_name" msgid="4093221025304876354">"የግድግዳ ወረቀት %1$d የ%2$d"</string> + <string name="wallpaper_accessibility_name" msgid="4093221025304876354">"ልጣፍ %1$d የ%2$d"</string> <string name="announce_selection" msgid="123723511662250539">"<xliff:g id="LABEL">%1$s</xliff:g> ተመርጧል"</string> <string name="wallpaper_delete" msgid="1459353972739215344">"ሰርዝ"</string> <string name="pick_image" msgid="6704438906027442697">"ምስል ይምረጡ"</string> <string name="pick_wallpaper" msgid="4628969645948454559">"የግድግዳ ወረቀቶች"</string> - <string name="crop_wallpaper" msgid="4882870800623585836">"የግድግዳ ወረቀት ይከርክሙ"</string> + <string name="crop_wallpaper" msgid="4882870800623585836">"ልጣፍ ይከርክሙ"</string> </resources> diff --git a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java index 44bfdf1f9..2bdf8f1cd 100644 --- a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java +++ b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java @@ -34,8 +34,6 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListAdapter; -import com.android.photos.BitmapRegionTileSource; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -49,39 +47,17 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter { Context mContext; LayoutInflater mLayoutInflater; - public static class SavedWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo { + public static class SavedWallpaperTile extends WallpaperPickerActivity.FileWallpaperInfo { private int mDbId; - private Drawable mThumb; - public SavedWallpaperTile(int dbId, Drawable thumb) { + public SavedWallpaperTile(int dbId, File target, Drawable thumb) { + super(target, thumb); mDbId = dbId; - mThumb = thumb; - } - @Override - public void onClick(WallpaperPickerActivity a) { - String imageFilename = a.getSavedImages().getImageFilename(mDbId); - File file = new File(a.getFilesDir(), imageFilename); - BitmapRegionTileSource.FilePathBitmapSource bitmapSource = - new BitmapRegionTileSource.FilePathBitmapSource(file.getAbsolutePath(), 1024); - a.setCropViewTileSource(bitmapSource, false, true, null); - } - @Override - public void onSave(WallpaperPickerActivity a) { - boolean finishActivityWhenDone = true; - String imageFilename = a.getSavedImages().getImageFilename(mDbId); - a.setWallpaper(imageFilename, finishActivityWhenDone); } + @Override public void onDelete(WallpaperPickerActivity a) { a.getSavedImages().deleteImage(mDbId); } - @Override - public boolean isSelectable() { - return true; - } - @Override - public boolean isNamelessWallpaper() { - return true; - } } public SavedWallpaperImages(Activity context) { @@ -98,7 +74,8 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter { SQLiteDatabase db = mDb.getReadableDatabase(); Cursor result = db.query(ImageDb.TABLE_NAME, new String[] { ImageDb.COLUMN_ID, - ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME }, // cols to return + ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME, + ImageDb.COLUMN_IMAGE_FILENAME}, // cols to return null, // select query null, // args to select query null, @@ -112,7 +89,9 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter { Bitmap thumb = BitmapFactory.decodeFile(file.getAbsolutePath()); if (thumb != null) { - mImages.add(new SavedWallpaperTile(result.getInt(0), new BitmapDrawable(thumb))); + mImages.add(new SavedWallpaperTile(result.getInt(0), + new File(mContext.getFilesDir(), result.getString(2)), + new BitmapDrawable(thumb))); } } result.close(); @@ -136,15 +115,7 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter { Log.e(TAG, "Error decoding thumbnail for wallpaper #" + position); } return WallpaperPickerActivity.createImageTileView( - mLayoutInflater, position, convertView, parent, thumbDrawable); - } - - public String getImageFilename(int id) { - Pair<String, String> filenames = getImageFilenames(id); - if (filenames != null) { - return filenames.second; - } - return null; + mLayoutInflater, convertView, parent, thumbDrawable); } private Pair<String, String> getImageFilenames(int id) { diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java index 561c4bb6a..d5c7cd93d 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java @@ -133,6 +133,14 @@ public class WallpaperCropActivity extends Activity { setCropViewTileSource(bitmapSource, true, false, onLoad); } + @Override + protected void onDestroy() { + if (mCropView != null) { + mCropView.destroy(); + } + super.onDestroy(); + } + public void setCropViewTileSource( final BitmapRegionTileSource.BitmapSource bitmapSource, final boolean touchEnabled, final boolean moveToLeft, final Runnable postExecute) { @@ -141,7 +149,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; } @@ -286,10 +308,10 @@ public class WallpaperCropActivity extends Activity { return 0; } - protected void setWallpaper(String filePath, final boolean finishActivityWhenDone) { - int rotation = getRotationFromExif(filePath); + protected void setWallpaper(Uri uri, final boolean finishActivityWhenDone) { + int rotation = getRotationFromExif(this, uri); BitmapCropTask cropTask = new BitmapCropTask( - this, filePath, null, rotation, 0, 0, true, false, null); + this, uri, null, rotation, 0, 0, true, false, null); final Point bounds = cropTask.getImageBounds(); Runnable onEndCrop = new Runnable() { public void run() { @@ -352,10 +374,13 @@ public class WallpaperCropActivity extends Activity { getWindowManager()); // Get the crop RectF cropRect = mCropView.getCrop(); + + Point inSize = mCropView.getSourceDimensions(); + int cropRotation = mCropView.getImageRotation(); float cropScale = mCropView.getWidth() / (float) cropRect.width(); - Point inSize = mCropView.getSourceDimensions(); + Matrix rotateMatrix = new Matrix(); rotateMatrix.setRotate(cropRotation); float[] rotatedInSize = new float[] { inSize.x, inSize.y }; @@ -363,6 +388,14 @@ public class WallpaperCropActivity extends Activity { rotatedInSize[0] = Math.abs(rotatedInSize[0]); rotatedInSize[1] = Math.abs(rotatedInSize[1]); + + // 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(rotatedInSize[0], cropRect.right); + cropRect.top = Math.max(0, cropRect.top); + cropRect.bottom = Math.min(rotatedInSize[1], cropRect.bottom); + // ADJUST CROP WIDTH // Extend the crop all the way to the right, for parallax // (or all the way to the left, in RTL) @@ -799,17 +832,28 @@ public class WallpaperCropActivity extends Activity { editor.commit(); suggestWallpaperDimension(getResources(), - sp, getWindowManager(), WallpaperManager.getInstance(this)); + sp, getWindowManager(), WallpaperManager.getInstance(this), true); } static public void suggestWallpaperDimension(Resources res, final SharedPreferences sharedPrefs, WindowManager windowManager, - final WallpaperManager wallpaperManager) { + final WallpaperManager wallpaperManager, boolean fallBackToDefaults) { final Point defaultWallpaperSize = getDefaultWallpaperSize(res, windowManager); // If we have saved a wallpaper width/height, use that instead - int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, defaultWallpaperSize.x); - int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, defaultWallpaperSize.y); + + int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, -1); + int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, -1); + + if (savedWidth == -1 || savedHeight == -1) { + if (!fallBackToDefaults) { + return; + } else { + savedWidth = defaultWallpaperSize.x; + savedHeight = defaultWallpaperSize.y; + } + } + if (savedWidth != wallpaperManager.getDesiredMinimumWidth() || savedHeight != wallpaperManager.getDesiredMinimumHeight()) { wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight); diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java index 013606a50..07285372e 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java @@ -17,6 +17,7 @@ package com.android.launcher3; import android.animation.LayoutTransition; +import android.annotation.TargetApi; import android.app.ActionBar; import android.app.Activity; import android.app.WallpaperInfo; @@ -61,12 +62,12 @@ import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.WindowManager; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; +import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.FrameLayout; import android.widget.HorizontalScrollView; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.ListAdapter; import android.widget.Toast; import com.android.photos.BitmapRegionTileSource; @@ -109,6 +110,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { public static abstract class WallpaperTileInfo { protected View mView; + public Drawable mThumb; + public void setView(View v) { mView = v; } @@ -194,10 +197,36 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } + public static class FileWallpaperInfo extends WallpaperTileInfo { + private File mFile; + + public FileWallpaperInfo(File target, Drawable thumb) { + mFile = target; + mThumb = thumb; + } + @Override + public void onClick(WallpaperPickerActivity a) { + BitmapRegionTileSource.UriBitmapSource bitmapSource = + new BitmapRegionTileSource.UriBitmapSource(a, Uri.fromFile(mFile), 1024); + a.setCropViewTileSource(bitmapSource, false, true, null); + } + @Override + public void onSave(WallpaperPickerActivity a) { + a.setWallpaper(Uri.fromFile(mFile), true); + } + @Override + public boolean isSelectable() { + return true; + } + @Override + public boolean isNamelessWallpaper() { + return true; + } + } + public static class ResourceWallpaperInfo extends WallpaperTileInfo { private Resources mResources; private int mResId; - private Drawable mThumb; public ResourceWallpaperInfo(Resources res, int resId, Drawable thumb) { mResources = res; @@ -237,8 +266,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } + @TargetApi(Build.VERSION_CODES.KITKAT) public static class DefaultWallpaperInfo extends WallpaperTileInfo { - public Drawable mThumb; public DefaultWallpaperInfo(Drawable thumb) { mThumb = thumb; } @@ -431,9 +460,9 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { }; // Populate the built-in wallpapers - ArrayList<ResourceWallpaperInfo> wallpapers = findBundledWallpapers(); + ArrayList<WallpaperTileInfo> wallpapers = findBundledWallpapers(); mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list); - BuiltInWallpapersAdapter ia = new BuiltInWallpapersAdapter(this, wallpapers); + SimpleWallpapersAdapter ia = new SimpleWallpapersAdapter(this, wallpapers); populateWallpapersFromAdapter(mWallpapersView, ia, false); // Populate the saved wallpapers @@ -484,20 +513,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { pickImageInfo.setView(pickImageTile); pickImageTile.setOnClickListener(mThumbnailOnClickListener); - // Add a tile for the default wallpaper - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - DefaultWallpaperInfo defaultWallpaperInfo = getDefaultWallpaper(); - if (defaultWallpaperInfo != null) { - FrameLayout defaultWallpaperTile = (FrameLayout) createImageTileView( - getLayoutInflater(), 0, null, mWallpapersView, defaultWallpaperInfo.mThumb); - setWallpaperItemPaddingToZero(defaultWallpaperTile); - defaultWallpaperTile.setTag(defaultWallpaperInfo); - mWallpapersView.addView(defaultWallpaperTile, 0); - defaultWallpaperTile.setOnClickListener(mThumbnailOnClickListener); - defaultWallpaperInfo.setView(defaultWallpaperTile); - } - } - // Select the first item; wait for a layout pass so that we initialize the dimensions of // cropView or the defaultWallpaperView first mCropView.addOnLayoutChangeListener(new OnLayoutChangeListener() { @@ -674,13 +689,16 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { new String[] { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC LIMIT 1"); + Bitmap thumb = null; - if (cursor.moveToNext()) { - int id = cursor.getInt(0); - thumb = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), - id, MediaStore.Images.Thumbnails.MINI_KIND, null); + if (cursor != null) { + if (cursor.moveToNext()) { + int id = cursor.getInt(0); + thumb = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), + id, MediaStore.Images.Thumbnails.MINI_KIND, null); + } + cursor.close(); } - cursor.close(); return thumb; } @@ -822,12 +840,26 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { final Context context = this; new AsyncTask<Void, Bitmap, Bitmap>() { protected Bitmap doInBackground(Void...args) { - int rotation = WallpaperCropActivity.getRotationFromExif(context, uri); - return createThumbnail(defaultSize, context, uri, null, null, 0, rotation, false); - + try { + int rotation = WallpaperCropActivity.getRotationFromExif(context, uri); + return createThumbnail(defaultSize, context, uri, null, null, 0, rotation, false); + } 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; + } } protected void onPostExecute(Bitmap thumb) { - if (thumb != null) { + if (!isCancelled() && thumb != null) { image.setImageBitmap(thumb); Drawable thumbDrawable = image.getDrawable(); thumbDrawable.setDither(true); @@ -886,27 +918,68 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { v.setOnLongClickListener(mLongClickListener); } - private ArrayList<ResourceWallpaperInfo> findBundledWallpapers() { - ArrayList<ResourceWallpaperInfo> bundledWallpapers = - new ArrayList<ResourceWallpaperInfo>(24); + private ArrayList<WallpaperTileInfo> findBundledWallpapers() { + final PackageManager pm = getPackageManager(); + final ArrayList<WallpaperTileInfo> bundled = new ArrayList<WallpaperTileInfo>(24); + + Partner partner = Partner.get(pm); + if (partner != null) { + final Resources partnerRes = partner.getResources(); + final int resId = partnerRes.getIdentifier(Partner.RES_WALLPAPERS, "array", + partner.getPackageName()); + if (resId != 0) { + addWallpapers(bundled, partnerRes, partner.getPackageName(), resId); + } + + // Add system wallpapers + File systemDir = partner.getWallpaperDirectory(); + if (systemDir != null && systemDir.isDirectory()) { + for (File file : systemDir.listFiles()) { + if (!file.isFile()) { + continue; + } + String name = file.getName(); + int dotPos = name.lastIndexOf('.'); + String extension = ""; + if (dotPos >= -1) { + extension = name.substring(dotPos); + name = name.substring(0, dotPos); + } + + if (name.endsWith("_small")) { + // it is a thumbnail + continue; + } + + File thumbnail = new File(systemDir, name + "_small" + extension); + Bitmap thumb = BitmapFactory.decodeFile(thumbnail.getAbsolutePath()); + if (thumb != null) { + bundled.add(new FileWallpaperInfo(file, new BitmapDrawable(thumb))); + } + } + } + } Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId(); if (r != null) { try { Resources wallpaperRes = getPackageManager().getResourcesForApplication(r.first); - bundledWallpapers = addWallpapers(wallpaperRes, r.first.packageName, r.second); + addWallpapers(bundled, wallpaperRes, r.first.packageName, r.second); } catch (PackageManager.NameNotFoundException e) { } } - // Add an entry for the default wallpaper (stored in system resources) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - ResourceWallpaperInfo defaultWallpaperInfo = getPreKKDefaultWallpaperInfo(); + if (partner == null || !partner.hideDefaultWallpaper()) { + // Add an entry for the default wallpaper (stored in system resources) + WallpaperTileInfo defaultWallpaperInfo = + (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) + ? getPreKKDefaultWallpaperInfo() + : getDefaultWallpaper(); if (defaultWallpaperInfo != null) { - bundledWallpapers.add(0, defaultWallpaperInfo); + bundled.add(0, defaultWallpaperInfo); } } - return bundledWallpapers; + return bundled; } private boolean writeImageToFileAsJpeg(File f, Bitmap b) { @@ -924,11 +997,27 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { return false; } + private File getDefaultThumbFile() { + return new File(getFilesDir(), Build.VERSION.SDK_INT + + "_" + DEFAULT_WALLPAPER_THUMBNAIL_FILENAME); + } + + private boolean saveDefaultWallpaperThumb(Bitmap b) { + // Delete old thumbnails. + new File(getFilesDir(), OLD_DEFAULT_WALLPAPER_THUMBNAIL_FILENAME).delete(); + new File(getFilesDir(), DEFAULT_WALLPAPER_THUMBNAIL_FILENAME).delete(); + + for (int i = Build.VERSION_CODES.JELLY_BEAN; i < Build.VERSION.SDK_INT; i++) { + new File(getFilesDir(), i + "_" + DEFAULT_WALLPAPER_THUMBNAIL_FILENAME).delete(); + } + return writeImageToFileAsJpeg(getDefaultThumbFile(), b); + } + private ResourceWallpaperInfo getPreKKDefaultWallpaperInfo() { Resources sysRes = Resources.getSystem(); int resId = sysRes.getIdentifier("default_wallpaper", "drawable", "android"); - File defaultThumbFile = new File(getFilesDir(), DEFAULT_WALLPAPER_THUMBNAIL_FILENAME); + File defaultThumbFile = getDefaultThumbFile(); Bitmap thumb = null; boolean defaultWallpaperExists = false; if (defaultThumbFile.exists()) { @@ -941,7 +1030,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { thumb = createThumbnail( defaultThumbSize, this, null, null, sysRes, resId, rotation, false); if (thumb != null) { - defaultWallpaperExists = writeImageToFileAsJpeg(defaultThumbFile, thumb); + defaultWallpaperExists = saveDefaultWallpaperThumb(thumb); } } if (defaultWallpaperExists) { @@ -950,18 +1039,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { return null; } + @TargetApi(Build.VERSION_CODES.KITKAT) private DefaultWallpaperInfo getDefaultWallpaper() { - File defaultThumbFile = new File(getFilesDir(), DEFAULT_WALLPAPER_THUMBNAIL_FILENAME); + File defaultThumbFile = getDefaultThumbFile(); Bitmap thumb = null; boolean defaultWallpaperExists = false; if (defaultThumbFile.exists()) { thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath()); defaultWallpaperExists = true; } else { - // Delete old thumbnail file, since we had a bug where the thumbnail wasn't being drawn - // before - new File(getFilesDir(), OLD_DEFAULT_WALLPAPER_THUMBNAIL_FILENAME).delete(); - Resources res = getResources(); Point defaultThumbSize = getDefaultThumbnailSize(res); Drawable wallpaperDrawable = WallpaperManager.getInstance(this).getBuiltInDrawable( @@ -975,7 +1061,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { c.setBitmap(null); } if (thumb != null) { - defaultWallpaperExists = writeImageToFileAsJpeg(defaultThumbFile, thumb); + defaultWallpaperExists = saveDefaultWallpaperThumb(thumb); } } if (defaultWallpaperExists) { @@ -998,10 +1084,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } - private ArrayList<ResourceWallpaperInfo> addWallpapers( - Resources res, String packageName, int listResId) { - ArrayList<ResourceWallpaperInfo> bundledWallpapers = - new ArrayList<ResourceWallpaperInfo>(24); + private void addWallpapers(ArrayList<WallpaperTileInfo> known, Resources res, + String packageName, int listResId) { final String[] extras = res.getStringArray(listResId); for (String extra : extras) { int resId = res.getIdentifier(extra, "drawable", packageName); @@ -1011,14 +1095,13 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { if (thumbRes != 0) { ResourceWallpaperInfo wallpaperInfo = new ResourceWallpaperInfo(res, resId, res.getDrawable(thumbRes)); - bundledWallpapers.add(wallpaperInfo); + known.add(wallpaperInfo); // Log.d(TAG, "add: [" + packageName + "]: " + extra + " (" + res + ")"); } } else { Log.e(TAG, "Couldn't find wallpaper " + extra); } } - return bundledWallpapers; } public CropView getCropView() { @@ -1048,37 +1131,24 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } - private static class BuiltInWallpapersAdapter extends BaseAdapter implements ListAdapter { - private LayoutInflater mLayoutInflater; - private ArrayList<ResourceWallpaperInfo> mWallpapers; + private static class SimpleWallpapersAdapter extends ArrayAdapter<WallpaperTileInfo> { + private final LayoutInflater mLayoutInflater; - BuiltInWallpapersAdapter(Activity activity, ArrayList<ResourceWallpaperInfo> wallpapers) { + SimpleWallpapersAdapter(Activity activity, ArrayList<WallpaperTileInfo> wallpapers) { + super(activity, R.layout.wallpaper_picker_item, wallpapers); mLayoutInflater = activity.getLayoutInflater(); - mWallpapers = wallpapers; - } - - public int getCount() { - return mWallpapers.size(); - } - - public ResourceWallpaperInfo getItem(int position) { - return mWallpapers.get(position); - } - - public long getItemId(int position) { - return position; } public View getView(int position, View convertView, ViewGroup parent) { - Drawable thumb = mWallpapers.get(position).mThumb; + Drawable thumb = getItem(position).mThumb; if (thumb == null) { Log.e(TAG, "Error decoding thumbnail for wallpaper #" + position); } - return createImageTileView(mLayoutInflater, position, convertView, parent, thumb); + return createImageTileView(mLayoutInflater, convertView, parent, thumb); } } - public static View createImageTileView(LayoutInflater layoutInflater, int position, + public static View createImageTileView(LayoutInflater layoutInflater, View convertView, ViewGroup parent, Drawable thumb) { View view; diff --git a/WallpaperPicker/src/com/android/photos/BitmapRegionTileSource.java b/WallpaperPicker/src/com/android/photos/BitmapRegionTileSource.java index 764156de0..66ece4ff6 100644 --- a/WallpaperPicker/src/com/android/photos/BitmapRegionTileSource.java +++ b/WallpaperPicker/src/com/android/photos/BitmapRegionTileSource.java @@ -283,9 +283,6 @@ public class BitmapRegionTileSource implements TiledImageRenderer.TileSource { } catch (FileNotFoundException e) { Log.e("BitmapRegionTileSource", "Failed to load URI " + mUri, e); return null; - } catch (IOException e) { - Log.e("BitmapRegionTileSource", "Failure while reading URI " + mUri, e); - return null; } } @Override |