diff options
author | Michael Jurka <mikejurka@google.com> | 2013-09-04 00:45:37 +0200 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2013-09-04 16:21:20 +0200 |
commit | eadbfc564d84aaf1d800da3d0d6edf6312f89648 (patch) | |
tree | 8bb3858af8f7e2d7bbcf8ccff4b8904856d1c376 /src/com/android/launcher3/WallpaperPickerActivity.java | |
parent | 8b3cd79082043a08c319f1550679d4078b7d509c (diff) | |
download | android_packages_apps_Trebuchet-eadbfc564d84aaf1d800da3d0d6edf6312f89648.tar.gz android_packages_apps_Trebuchet-eadbfc564d84aaf1d800da3d0d6edf6312f89648.tar.bz2 android_packages_apps_Trebuchet-eadbfc564d84aaf1d800da3d0d6edf6312f89648.zip |
Move wallpapers to external activity
Also renaming Launcher's ApplicationInfo to
AppInfo since ApplicationInfo is already a
framework class
Change-Id: Ib3e91d2ba4ace458d790a26c0ce850870fd3f146
Diffstat (limited to 'src/com/android/launcher3/WallpaperPickerActivity.java')
-rw-r--r-- | src/com/android/launcher3/WallpaperPickerActivity.java | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java index 536775ace..8f323e809 100644 --- a/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/src/com/android/launcher3/WallpaperPickerActivity.java @@ -23,6 +23,7 @@ import android.content.ComponentName; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; @@ -34,6 +35,7 @@ import android.graphics.drawable.LevelListDrawable; import android.net.Uri; import android.os.Bundle; import android.util.Log; +import android.util.Pair; import android.view.Display; import android.view.LayoutInflater; import android.view.Menu; @@ -63,8 +65,9 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { private static final int PICK_WALLPAPER_THIRD_PARTY_ACTIVITY = 6; private static final float WALLPAPER_SCREENS_SPAN = 2f; - private ArrayList<Integer> mThumbs; + private ArrayList<Drawable> mThumbs; private ArrayList<Integer> mImages; + private Resources mWallpaperResources; private View mSelectedThumb; private CropView mCropView; @@ -98,7 +101,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { meta.mGalleryImageUri, 1024, 0), null); mCropView.setTouchEnabled(true); } else { - BitmapRegionTileSource source = new BitmapRegionTileSource( + BitmapRegionTileSource source = new BitmapRegionTileSource(mWallpaperResources, WallpaperPickerActivity.this, meta.mWallpaperResId, 1024, 0); mCropView.setTileSource(source, null); Point wallpaperSize = getDefaultWallpaperSize(getResources(), getWindowManager()); @@ -311,8 +314,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { updateWallpaperDimensions(0, 0); } }; - BitmapCropTask cropTask = new BitmapCropTask(meta.mWallpaperResId, - crop, outSize.x, outSize.y, + BitmapCropTask cropTask = new BitmapCropTask(mWallpaperResources, + meta.mWallpaperResId, crop, outSize.x, outSize.y, true, false, onEndCrop); cropTask.execute(); setResult(Activity.RESULT_OK); @@ -389,22 +392,35 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } private void findWallpapers() { - mThumbs = new ArrayList<Integer>(24); + mThumbs = new ArrayList<Drawable>(24); mImages = new ArrayList<Integer>(24); - final Resources resources = getResources(); + Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId(); + if (r != null) { + try { + mWallpaperResources = getPackageManager().getResourcesForApplication(r.first); + addWallpapers(mWallpaperResources, r.first.packageName, r.second); + } catch (PackageManager.NameNotFoundException e) { + } + } + } + + public Pair<ApplicationInfo, Integer> getWallpaperArrayResourceId() { // Context.getPackageName() may return the "original" package name, // com.android.launcher3; Resources needs the real package name, // com.android.launcher3. So we ask Resources for what it thinks the // package name should be. - final String packageName = resources.getResourcePackageName(R.array.wallpapers); - - addWallpapers(resources, packageName, R.array.wallpapers); - addWallpapers(resources, packageName, R.array.extra_wallpapers); + final String packageName = getResources().getResourcePackageName(R.array.wallpapers); + try { + ApplicationInfo info = getPackageManager().getApplicationInfo(packageName, 0); + return new Pair<ApplicationInfo, Integer>(info, R.array.wallpapers); + } catch (PackageManager.NameNotFoundException e) { + return null; + } } - private void addWallpapers(Resources resources, String packageName, int list) { - final String[] extras = resources.getStringArray(list); + private void addWallpapers(Resources resources, String packageName, int listResId) { + final String[] extras = resources.getStringArray(listResId); for (String extra : extras) { int res = resources.getIdentifier(extra, "drawable", packageName); if (res != 0) { @@ -412,7 +428,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { "drawable", packageName); if (thumbRes != 0) { - mThumbs.add(thumbRes); + mThumbs.add(resources.getDrawable(thumbRes)); mImages.add(res); // Log.d(TAG, "add: [" + packageName + "]: " + extra + " (" + res + ")"); } @@ -537,14 +553,12 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { ImageView image = (ImageView) view.findViewById(R.id.wallpaper_image); - int thumbRes = mThumbs.get(position); - image.setImageResource(thumbRes); - Drawable thumbDrawable = image.getDrawable(); + Drawable thumbDrawable = mThumbs.get(position); if (thumbDrawable != null) { + image.setImageDrawable(thumbDrawable); thumbDrawable.setDither(true); } else { - Log.e(TAG, "Error decoding thumbnail resId=" + thumbRes + " for wallpaper #" - + position); + Log.e(TAG, "Error decoding thumbnail for wallpaper #" + position); } return view; |