diff options
author | Daniel Sandler <dsandler@google.com> | 2009-09-11 15:59:22 -0400 |
---|---|---|
committer | Daniel Sandler <dsandler@google.com> | 2009-09-22 21:01:44 -0400 |
commit | 8f141b49ea4b794d160f1112887b79c65947f194 (patch) | |
tree | 64b55e20b4d49bae9b8b741aa2952f6bfa8ea308 | |
parent | 533e2728352fc55a14e4f1b689a916cbd7a58f12 (diff) | |
download | android_packages_apps_Trebuchet-8f141b49ea4b794d160f1112887b79c65947f194.tar.gz android_packages_apps_Trebuchet-8f141b49ea4b794d160f1112887b79c65947f194.tar.bz2 android_packages_apps_Trebuchet-8f141b49ea4b794d160f1112887b79c65947f194.zip |
Live wallpaper picker using a Gallery of thumbnails.
Note: live wallpapers without thumbnails are shown with some thrilling debug
information instead. TODO: add thumbnails for other LWs (and create a more
appealing placeholder for any future LW without a thumbnail).
-rw-r--r-- | res/layout/live_wallpaper_content.xml | 3 | ||||
-rw-r--r-- | src/com/android/launcher2/LiveWallpaperPickActivity.java | 69 |
2 files changed, 46 insertions, 26 deletions
diff --git a/res/layout/live_wallpaper_content.xml b/res/layout/live_wallpaper_content.xml index cbb79b41c..ea3041e32 100644 --- a/res/layout/live_wallpaper_content.xml +++ b/res/layout/live_wallpaper_content.xml @@ -44,8 +44,9 @@ </FrameLayout> <Gallery android:id="@+id/gallery" + android:gravity="fill" android:layout_width="fill_parent" - android:layout_height="wrap_content" /> + android:layout_height="160dip" /> <LinearLayout android:orientation="horizontal" diff --git a/src/com/android/launcher2/LiveWallpaperPickActivity.java b/src/com/android/launcher2/LiveWallpaperPickActivity.java index d311a2193..fc61af840 100644 --- a/src/com/android/launcher2/LiveWallpaperPickActivity.java +++ b/src/com/android/launcher2/LiveWallpaperPickActivity.java @@ -32,6 +32,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.graphics.drawable.Drawable; +import android.graphics.drawable.BitmapDrawable; import android.graphics.Bitmap; import android.os.Binder; import android.os.Bundle; @@ -44,6 +45,7 @@ import android.service.wallpaper.IWallpaperEngine; import android.service.wallpaper.IWallpaperService; import android.service.wallpaper.WallpaperService; import android.service.wallpaper.WallpaperSettingsActivity; +import android.util.DisplayMetrics; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -87,7 +89,7 @@ public class LiveWallpaperPickActivity private ArrayList<Intent> mWallpaperIntents; private ArrayList<WallpaperInfo> mWallpaperInfos; - private ArrayList<Bitmap> mThumbBitmaps; + private ArrayList<Drawable> mThumbnails; class WallpaperConnection extends IWallpaperConnection.Stub implements ServiceConnection { @@ -180,7 +182,7 @@ public class LiveWallpaperPickActivity } public int getCount() { - return mThumbBitmaps.size(); + return mThumbnails.size(); } public Object getItem(int position) { @@ -200,15 +202,22 @@ public class LiveWallpaperPickActivity image = (ImageView) convertView; } - image.setImageBitmap(mThumbBitmaps.get(position)); + image.setImageDrawable(mThumbnails.get(position)); image.getDrawable().setDither(true); + + image.setAdjustViewBounds(true); + image.setScaleType(ImageView.ScaleType.FIT_CENTER); + image.setLayoutParams(new Gallery.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.FILL_PARENT)); + return image; } } private void findLiveWallpapers() { - mThumbBitmaps = new ArrayList<Bitmap>(24); + mThumbnails = new ArrayList<Drawable>(24); List<ResolveInfo> list = mPackageManager.queryIntentServices(getTargetIntent(), PackageManager.GET_META_DATA); @@ -217,7 +226,9 @@ public class LiveWallpaperPickActivity mWallpaperInfos = new ArrayList<WallpaperInfo>(list.size()); int listSize = list.size(); - Log.d(TAG, String.format("findLiveWallpapers: found %d wallpaper services", listSize)); + DisplayMetrics metrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(metrics); + for (int i = 0; i < listSize; i++) { ResolveInfo resolveInfo = list.get(i); ComponentInfo ci = resolveInfo.serviceInfo; @@ -231,26 +242,39 @@ public class LiveWallpaperPickActivity Log.w(TAG, "Skipping wallpaper " + ci, e); continue; } - String packageName = ci.applicationInfo.packageName; - String className = ci.name; - Log.d(TAG, String.format("findLiveWallpapers: [%d] pkg=%s cls=%s", - i, packageName, className)); + + String packageName = winfo.getPackageName(); + String className = winfo.getServiceName(); Intent intent = new Intent(getTargetIntent()); intent.setClassName(packageName, className); mWallpaperIntents.add(intent); mWallpaperInfos.add(winfo); - Bitmap thumb = Bitmap.createBitmap(240,160,Bitmap.Config.ARGB_8888); - android.graphics.Canvas can = new android.graphics.Canvas(thumb); - android.graphics.Paint pt = new android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG|android.graphics.Paint.DITHER_FLAG); - pt.setARGB(255, 0, 0, 255); - can.drawPaint(pt); - pt.setARGB(255, 255, 255, 255); - pt.setTextSize(12); - can.drawText(className, 16, 150, pt); - pt.setTextSize(80); - can.drawText(String.format("%d", i), 100,100, pt); - mThumbBitmaps.add(thumb); + Drawable thumb = winfo.loadThumbnail(mPackageManager); + if (null == thumb) { + // TODO dsandler: replace with pretty placeholder + Bitmap thumbBit = Bitmap.createBitmap( + (int)(240 * metrics.density), + (int)(240 * metrics.density), + Bitmap.Config.ARGB_8888); + android.graphics.Canvas can = new android.graphics.Canvas(thumbBit); + android.graphics.Paint pt = new android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG|android.graphics.Paint.DITHER_FLAG); + pt.setARGB(255, 0, 0, 255); + can.drawPaint(pt); + pt.setARGB(255, 255, 255, 255); + pt.setTextSize(12 * metrics.density); + can.drawText(className, + (int)(12 * metrics.density), + (int)(thumbBit.getHeight()-12 * metrics.density), + pt); + pt.setTextSize(100 * metrics.density); + can.drawText(String.format("#%d", i), + (int)(thumbBit.getWidth()*0.3), + (int)(thumbBit.getHeight()*0.5), + pt); + thumb = new BitmapDrawable(thumbBit); + } + mThumbnails.add(thumb); } @@ -320,8 +344,6 @@ public class LiveWallpaperPickActivity } public void onItemSelected(AdapterView parent, View v, int position, long id) { - Log.d(TAG, String.format("onItemSelected: position=%d", position)); - mSelectedIntent = mWallpaperIntents.get(position); mSelectedInfo = mWallpaperInfos.get(position); mConfigureButton.setEnabled(mSelectedInfo != null @@ -338,9 +360,6 @@ public class LiveWallpaperPickActivity } public void onClick(View v) { // "Set" button - Log.d(TAG, "Set clicked"); - -// mSelectedIntent = mWallpaperIntents.get(mGallery.getSelectedItemPosition()); if (v.getId() == R.id.set) { if (mSelectedIntent != null) { try { |