From 998e4ff3dca60d65e94fa2ec4a35cb258124318b Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Wed, 18 Sep 2013 16:04:36 +0200 Subject: Add live wallpapers and third-party pickers to bottom strip Bug: 10742727 Bug: 10805463 Change-Id: I961344b34fff3b183380caf3508d23b05c1ca26c --- res/layout/live_wallpaper_picker_item.xml | 47 ++++ res/layout/third_party_wallpaper_picker_item.xml | 38 ++++ res/layout/wallpaper_picker.xml | 19 +- res/layout/wallpaper_picker_gallery_item.xml | 4 +- res/values/colors.xml | 1 + .../launcher3/LiveWallpaperListAdapter.java | 237 +++++++++++++++++++++ .../ThirdPartyWallpaperPickerListAdapter.java | 117 ++++++++++ .../android/launcher3/WallpaperPickerActivity.java | 187 ++++++++-------- 8 files changed, 559 insertions(+), 91 deletions(-) create mode 100644 res/layout/live_wallpaper_picker_item.xml create mode 100644 res/layout/third_party_wallpaper_picker_item.xml create mode 100644 src/com/android/launcher3/LiveWallpaperListAdapter.java create mode 100644 src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java diff --git a/res/layout/live_wallpaper_picker_item.xml b/res/layout/live_wallpaper_picker_item.xml new file mode 100644 index 000000000..29aa12ca2 --- /dev/null +++ b/res/layout/live_wallpaper_picker_item.xml @@ -0,0 +1,47 @@ + + + + + + + + diff --git a/res/layout/third_party_wallpaper_picker_item.xml b/res/layout/third_party_wallpaper_picker_item.xml new file mode 100644 index 000000000..c2aeade9e --- /dev/null +++ b/res/layout/third_party_wallpaper_picker_item.xml @@ -0,0 +1,38 @@ + + + + + + + diff --git a/res/layout/wallpaper_picker.xml b/res/layout/wallpaper_picker.xml index a0672f649..53c529c2a 100644 --- a/res/layout/wallpaper_picker.xml +++ b/res/layout/wallpaper_picker.xml @@ -50,10 +50,23 @@ - + android:orientation="horizontal" > + + + + + android:textColor="@android:color/white"/> diff --git a/res/values/colors.xml b/res/values/colors.xml index bd561edce..01fd64c7c 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -32,4 +32,5 @@ #FFF #FFF + #66000000 diff --git a/src/com/android/launcher3/LiveWallpaperListAdapter.java b/src/com/android/launcher3/LiveWallpaperListAdapter.java new file mode 100644 index 000000000..a6facaa02 --- /dev/null +++ b/src/com/android/launcher3/LiveWallpaperListAdapter.java @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.app.WallpaperInfo; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; +import android.os.AsyncTask; +import android.service.wallpaper.WallpaperService; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.ListAdapter; +import android.widget.TextView; + +import org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter { + private static final String LOG_TAG = "LiveWallpaperListAdapter"; + + private final LayoutInflater mInflater; + private final PackageManager mPackageManager; + + private List mWallpapers; + + @SuppressWarnings("unchecked") + public LiveWallpaperListAdapter(Context context) { + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mPackageManager = context.getPackageManager(); + + List list = mPackageManager.queryIntentServices( + new Intent(WallpaperService.SERVICE_INTERFACE), + PackageManager.GET_META_DATA); + + mWallpapers = generatePlaceholderViews(list.size()); + + new LiveWallpaperEnumerator(context).execute(list); + } + + private List generatePlaceholderViews(int amount) { + ArrayList list = new ArrayList(amount); + for (int i = 0; i < amount; i++) { + LiveWallpaperInfo info = new LiveWallpaperInfo(); + list.add(info); + } + return list; + } + + public int getCount() { + if (mWallpapers == null) { + return 0; + } + return mWallpapers.size(); + } + + public Object getItem(int position) { + return mWallpapers.get(position); + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + View view; + + if (convertView == null) { + view = mInflater.inflate(R.layout.live_wallpaper_picker_item, parent, false); + } else { + view = convertView; + } + + WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view); + + LiveWallpaperInfo wallpaperInfo = mWallpapers.get(position); + ImageView image = (ImageView) view.findViewById(R.id.wallpaper_image); + ImageView icon = (ImageView) view.findViewById(R.id.wallpaper_icon); + if (wallpaperInfo.thumbnail != null) { + image.setImageDrawable(wallpaperInfo.thumbnail); + icon.setVisibility(View.GONE); + } else { + icon.setImageDrawable(wallpaperInfo.info.loadIcon(mPackageManager)); + icon.setVisibility(View.VISIBLE); + } + + TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label); + label.setText(wallpaperInfo.info.loadLabel(mPackageManager)); + + return view; + } + + public class LiveWallpaperInfo { + public Drawable thumbnail; + public WallpaperInfo info; + public Intent intent; + } + + private class LiveWallpaperEnumerator extends + AsyncTask, LiveWallpaperInfo, Void> { + private Context mContext; + private int mWallpaperPosition; + + public LiveWallpaperEnumerator(Context context) { + super(); + mContext = context; + mWallpaperPosition = 0; + } + + @Override + protected Void doInBackground(List... params) { + final PackageManager packageManager = mContext.getPackageManager(); + + List list = params[0]; + + Collections.sort(list, new Comparator() { + final Collator mCollator; + + { + mCollator = Collator.getInstance(); + } + + public int compare(ResolveInfo info1, ResolveInfo info2) { + return mCollator.compare(info1.loadLabel(packageManager), + info2.loadLabel(packageManager)); + } + }); + + for (ResolveInfo resolveInfo : list) { + WallpaperInfo info = null; + try { + info = new WallpaperInfo(mContext, resolveInfo); + } catch (XmlPullParserException e) { + Log.w(LOG_TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); + continue; + } catch (IOException e) { + Log.w(LOG_TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); + continue; + } + + LiveWallpaperInfo wallpaper = new LiveWallpaperInfo(); + wallpaper.intent = new Intent(WallpaperService.SERVICE_INTERFACE); + wallpaper.intent.setClassName(info.getPackageName(), info.getServiceName()); + wallpaper.info = info; + + Drawable thumb = info.loadThumbnail(packageManager); + // TODO: generate a default thumb + /* + final Resources res = mContext.getResources(); + Canvas canvas = new Canvas(); + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); + paint.setTextAlign(Paint.Align.CENTER); + BitmapDrawable galleryIcon = (BitmapDrawable) res.getDrawable( + R.drawable.livewallpaper_placeholder); + if (thumb == null) { + int thumbWidth = res.getDimensionPixelSize( + R.dimen.live_wallpaper_thumbnail_width); + int thumbHeight = res.getDimensionPixelSize( + R.dimen.live_wallpaper_thumbnail_height); + + Bitmap thumbnail = Bitmap.createBitmap(thumbWidth, thumbHeight, + Bitmap.Config.ARGB_8888); + + paint.setColor(res.getColor(R.color.live_wallpaper_thumbnail_background)); + canvas.setBitmap(thumbnail); + canvas.drawPaint(paint); + + galleryIcon.setBounds(0, 0, thumbWidth, thumbHeight); + galleryIcon.setGravity(Gravity.CENTER); + galleryIcon.draw(canvas); + + String title = info.loadLabel(packageManager).toString(); + + paint.setColor(res.getColor(R.color.live_wallpaper_thumbnail_text_color)); + paint.setTextSize( + res.getDimensionPixelSize(R.dimen.live_wallpaper_thumbnail_text_size)); + + canvas.drawText(title, (int) (thumbWidth * 0.5), + thumbHeight - res.getDimensionPixelSize( + R.dimen.live_wallpaper_thumbnail_text_offset), paint); + + thumb = new BitmapDrawable(res, thumbnail); + }*/ + wallpaper.thumbnail = thumb; + publishProgress(wallpaper); + } + + return null; + } + + @Override + protected void onProgressUpdate(LiveWallpaperInfo...infos) { + for (LiveWallpaperInfo info : infos) { + info.thumbnail.setDither(true); + if (mWallpaperPosition < mWallpapers.size()) { + mWallpapers.set(mWallpaperPosition, info); + } else { + mWallpapers.add(info); + } + mWallpaperPosition++; + if (mWallpaperPosition == getCount()) { + LiveWallpaperListAdapter.this.notifyDataSetChanged(); + } + } + } + } +} diff --git a/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java b/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java new file mode 100644 index 000000000..9fd0d0a5f --- /dev/null +++ b/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.FrameLayout; +import android.widget.ListAdapter; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +public class ThirdPartyWallpaperPickerListAdapter extends BaseAdapter implements ListAdapter { + private static final String LOG_TAG = "LiveWallpaperListAdapter"; + + private final LayoutInflater mInflater; + private final PackageManager mPackageManager; + + private List mThirdPartyWallpaperPickers = new ArrayList(); + + public ThirdPartyWallpaperPickerListAdapter(Context context) { + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mPackageManager = context.getPackageManager(); + final PackageManager pm = mPackageManager; + + final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER); + final List apps = + pm.queryIntentActivities(pickWallpaperIntent, 0); + + // Get list of image picker intents + Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT); + pickImageIntent.setType("image/*"); + final List imagePickerActivities = + pm.queryIntentActivities(pickImageIntent, 0); + final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()]; + for (int i = 0; i < imagePickerActivities.size(); i++) { + ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo; + imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name); + } + + outerLoop: + for (ResolveInfo info : apps) { + final ComponentName itemComponentName = + new ComponentName(info.activityInfo.packageName, info.activityInfo.name); + final String itemPackageName = itemComponentName.getPackageName(); + // Exclude anything from our own package, and the old Launcher, + // and live wallpaper picker + if (itemPackageName.equals(context.getPackageName()) || + itemPackageName.equals("com.android.launcher") || + itemPackageName.equals("com.android.wallpaper.livepicker")) { + continue; + } + // Exclude any package that already responds to the image picker intent + for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) { + if (itemPackageName.equals( + imagePickerActivityInfo.activityInfo.packageName)) { + continue outerLoop; + } + } + mThirdPartyWallpaperPickers.add(info); + } + } + + public int getCount() { + return mThirdPartyWallpaperPickers.size(); + } + + public Object getItem(int position) { + return mThirdPartyWallpaperPickers.get(position); + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + View view; + + if (convertView == null) { + view = mInflater.inflate(R.layout.third_party_wallpaper_picker_item, parent, false); + } else { + view = convertView; + } + + WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view); + + ResolveInfo info = mThirdPartyWallpaperPickers.get(position); + TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label); + label.setText(info.loadLabel(mPackageManager)); + label.setCompoundDrawablesWithIntrinsicBounds( + null, info.loadIcon(mPackageManager), null, null); + return view; + } +} diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java index 824dea642..777460933 100644 --- a/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/src/com/android/launcher3/WallpaperPickerActivity.java @@ -19,6 +19,8 @@ package com.android.launcher3; import android.animation.LayoutTransition; import android.app.ActionBar; import android.app.Activity; +import android.app.WallpaperInfo; +import android.app.WallpaperManager; import android.content.ComponentName; import android.content.Intent; import android.content.pm.ActivityInfo; @@ -27,8 +29,10 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.database.Cursor; +import android.database.DataSetObserver; import android.graphics.Bitmap; import android.graphics.Point; +import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; @@ -66,6 +70,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { private static final int IMAGE_PICK = 5; private static final int PICK_WALLPAPER_THIRD_PARTY_ACTIVITY = 6; + private static final int PICK_LIVE_WALLPAPER = 7; private static final String TEMP_WALLPAPER_TILES = "TEMP_WALLPAPER_TILES"; private ArrayList mBundledWallpaperThumbs; @@ -85,12 +90,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { ArrayList mTempWallpaperTiles = new ArrayList(); private SavedWallpaperImages mSavedImages; + private WallpaperInfo mLiveWallpaperInfoOnPickerLaunch; private static class ThumbnailMetaData { - public boolean mLaunchesGallery; + public TileType mTileType; public Uri mWallpaperUri; public int mSavedWallpaperDbId; public int mWallpaperResId; + public LiveWallpaperListAdapter.LiveWallpaperInfo mLiveWallpaperInfo; + public ResolveInfo mThirdPartyWallpaperPickerInfo; } // called by onCreate; this is subclassed to overwrite WallpaperCropActivity @@ -142,29 +150,38 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } ThumbnailMetaData meta = (ThumbnailMetaData) v.getTag(); - - if (!meta.mLaunchesGallery) { + if (meta.mTileType == TileType.WALLPAPER_RESOURCE || + meta.mTileType == TileType.SAVED_WALLPAPER || + meta.mTileType == TileType.WALLPAPER_URI) { mSelectedThumb = v; v.setSelected(true); } - - if (meta.mLaunchesGallery) { + if (meta.mTileType == TileType.PICK_IMAGE) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); Utilities.startActivityForResultSafely( WallpaperPickerActivity.this, intent, IMAGE_PICK); - } else if (meta.mWallpaperUri != null) { + } else if (meta.mTileType == TileType.WALLPAPER_URI) { mCropView.setTileSource(new BitmapRegionTileSource(WallpaperPickerActivity.this, meta.mWallpaperUri, 1024, 0), null); mCropView.setTouchEnabled(true); - } else if (meta.mSavedWallpaperDbId != 0) { + } else if (meta.mTileType == TileType.SAVED_WALLPAPER) { String imageFilename = mSavedImages.getImageFilename(meta.mSavedWallpaperDbId); File file = new File(getFilesDir(), imageFilename); mCropView.setTileSource(new BitmapRegionTileSource(WallpaperPickerActivity.this, file.getAbsolutePath(), 1024, 0), null); mCropView.moveToLeft(); mCropView.setTouchEnabled(false); - } else if (meta.mWallpaperResId != 0) { + } else if (meta.mTileType == TileType.LIVE_WALLPAPER) { + Intent preview = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); + preview.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, + meta.mLiveWallpaperInfo.info.getComponent()); + WallpaperManager wm = + WallpaperManager.getInstance(WallpaperPickerActivity.this); + mLiveWallpaperInfoOnPickerLaunch = wm.getWallpaperInfo(); + Utilities.startActivityForResultSafely(WallpaperPickerActivity.this, + preview, PICK_LIVE_WALLPAPER); + } else if (meta.mTileType == TileType.WALLPAPER_RESOURCE) { BitmapRegionTileSource source = new BitmapRegionTileSource(mWallpaperResources, WallpaperPickerActivity.this, meta.mWallpaperResId, 1024, 0); mCropView.setTileSource(source, null); @@ -175,6 +192,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { wallpaperSize.x, wallpaperSize.y, false); mCropView.setScale(wallpaperSize.x / crop.width()); mCropView.setTouchEnabled(false); + } else if (meta.mTileType == TileType.THIRD_PARTY_WALLPAPER_PICKER) { + ResolveInfo info = meta.mThirdPartyWallpaperPickerInfo; + + final ComponentName itemComponentName = new ComponentName( + info.activityInfo.packageName, info.activityInfo.name); + Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER); + launchIntent.setComponent(itemComponentName); + Utilities.startActivityForResultSafely(WallpaperPickerActivity.this, + launchIntent, PICK_WALLPAPER_THIRD_PARTY_ACTIVITY); } } }; @@ -202,7 +228,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { findBundledWallpapers(); mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list); ImageAdapter ia = new ImageAdapter(this, mBundledWallpaperThumbs); - populateWallpapersFromAdapter(mWallpapersView, ia, mBundledWallpaperResIds, true, false); + populateWallpapersFromAdapter( + mWallpapersView, ia, mBundledWallpaperResIds, TileType.WALLPAPER_RESOURCE, false, true); // Populate the saved wallpapers mSavedImages = new SavedWallpaperImages(this); @@ -210,13 +237,34 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { ArrayList savedWallpaperThumbs = mSavedImages.getThumbnails(); ArrayList savedWallpaperIds = mSavedImages.getImageIds(); ia = new ImageAdapter(this, savedWallpaperThumbs); - populateWallpapersFromAdapter(mWallpapersView, ia, savedWallpaperIds, false, true); + populateWallpapersFromAdapter( + mWallpapersView, ia, savedWallpaperIds, TileType.SAVED_WALLPAPER, true, true); + + // Populate the live wallpapers + final LinearLayout liveWallpapersView = (LinearLayout) findViewById(R.id.live_wallpaper_list); + final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(this); + a.registerDataSetObserver(new DataSetObserver() { + public void onChanged() { + liveWallpapersView.removeAllViews(); + populateWallpapersFromAdapter( + liveWallpapersView, a, null, TileType.LIVE_WALLPAPER, false, false); + } + }); + + // Populate the third-party wallpaper pickers + final LinearLayout thirdPartyWallpapersView = + (LinearLayout) findViewById(R.id.third_party_wallpaper_list); + final ThirdPartyWallpaperPickerListAdapter ta = + new ThirdPartyWallpaperPickerListAdapter(this); + populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, null, + TileType.THIRD_PARTY_WALLPAPER_PICKER, false, false); // Add a tile for the Gallery + LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list); FrameLayout galleryThumbnail = (FrameLayout) getLayoutInflater(). - inflate(R.layout.wallpaper_picker_gallery_item, mWallpapersView, false); + inflate(R.layout.wallpaper_picker_gallery_item, masterWallpaperList, false); setWallpaperItemPaddingToZero(galleryThumbnail); - mWallpapersView.addView(galleryThumbnail, 0); + masterWallpaperList.addView(galleryThumbnail, 0); // Make its background the last photo taken on external storage Bitmap lastPhoto = getThumbnailOfLastPhoto(); @@ -224,10 +272,12 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { ImageView galleryThumbnailBg = (ImageView) galleryThumbnail.findViewById(R.id.wallpaper_image); galleryThumbnailBg.setImageBitmap(getThumbnailOfLastPhoto()); + int colorOverlay = getResources().getColor(R.color.wallpaper_picker_translucent_gray); + galleryThumbnailBg.setColorFilter(colorOverlay, PorterDuff.Mode.SRC_ATOP); } ThumbnailMetaData meta = new ThumbnailMetaData(); - meta.mLaunchesGallery = true; + meta.mTileType = TileType.PICK_IMAGE; galleryThumbnail.setTag(meta); galleryThumbnail.setOnClickListener(mThumbnailOnClickListener); @@ -247,7 +297,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { @Override public void onClick(View v) { ThumbnailMetaData meta = (ThumbnailMetaData) mSelectedThumb.getTag(); - if (meta.mLaunchesGallery) { + if (meta.mTileType == TileType.PICK_IMAGE) { // shouldn't be selected, but do nothing } else if (meta.mWallpaperUri != null) { boolean finishActivityWhenDone = true; @@ -385,24 +435,39 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } - private void populateWallpapersFromAdapter(ViewGroup parent, ImageAdapter ia, - ArrayList imageIds, boolean imagesAreResources, boolean addLongPressHandler) { - for (int i = 0; i < ia.getCount(); i++) { - FrameLayout thumbnail = (FrameLayout) ia.getView(i, null, parent); + private enum TileType { + PICK_IMAGE, + WALLPAPER_RESOURCE, + WALLPAPER_URI, + SAVED_WALLPAPER, + LIVE_WALLPAPER, + THIRD_PARTY_WALLPAPER_PICKER + }; + + private void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter, + ArrayList imageIds, TileType tileType, boolean addLongPressHandler, boolean selectFirstTile) { + for (int i = 0; i < adapter.getCount(); i++) { + FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent); parent.addView(thumbnail, i); ThumbnailMetaData meta = new ThumbnailMetaData(); - if (imagesAreResources) { + meta.mTileType = tileType; + if (tileType == TileType.WALLPAPER_RESOURCE) { meta.mWallpaperResId = imageIds.get(i); - } else { + } else if (tileType == TileType.SAVED_WALLPAPER) { meta.mSavedWallpaperDbId = imageIds.get(i); + } else if (tileType == TileType.LIVE_WALLPAPER) { + meta.mLiveWallpaperInfo = + (LiveWallpaperListAdapter.LiveWallpaperInfo) adapter.getItem(i); + } else if (tileType == TileType.THIRD_PARTY_WALLPAPER_PICKER) { + meta.mThirdPartyWallpaperPickerInfo = (ResolveInfo) adapter.getItem(i); } thumbnail.setTag(meta); if (addLongPressHandler) { addLongPressHandler(thumbnail); } thumbnail.setOnClickListener(mThumbnailOnClickListener); - if (i == 0) { + if (i == 0 && selectFirstTile) { mThumbnailOnClickListener.onClick(thumbnail); } } @@ -452,9 +517,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } else { Log.e(TAG, "Error loading thumbnail for uri=" + uri); } - mWallpapersView.addView(pickedImageThumbnail, 1); + mWallpapersView.addView(pickedImageThumbnail, 0); ThumbnailMetaData meta = new ThumbnailMetaData(); + meta.mTileType = TileType.WALLPAPER_URI; meta.mWallpaperUri = uri; pickedImageThumbnail.setTag(meta); pickedImageThumbnail.setOnClickListener(mThumbnailOnClickListener); @@ -466,13 +532,24 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { Uri uri = data.getData(); addTemporaryWallpaperTile(uri); } else if (requestCode == PICK_WALLPAPER_THIRD_PARTY_ACTIVITY) { - // No result code is returned; just return setResult(RESULT_OK); finish(); + } else if (requestCode == PICK_LIVE_WALLPAPER) { + WallpaperManager wm = WallpaperManager.getInstance(this); + final WallpaperInfo oldLiveWallpaper = mLiveWallpaperInfoOnPickerLaunch; + WallpaperInfo newLiveWallpaper = wm.getWallpaperInfo(); + // Try to figure out if a live wallpaper was set; + if (newLiveWallpaper != null && + (oldLiveWallpaper == null || + !oldLiveWallpaper.getComponent().equals(newLiveWallpaper.getComponent()))) { + // Return if a live wallpaper was set + setResult(RESULT_OK); + finish(); + } } } - private static void setWallpaperItemPaddingToZero(FrameLayout frameLayout) { + static void setWallpaperItemPaddingToZero(FrameLayout frameLayout) { frameLayout.setPadding(0, 0, 0, 0); frameLayout.setForeground(new ZeroPaddingDrawable(frameLayout.getForeground())); } @@ -481,68 +558,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { v.setOnLongClickListener(mLongClickListener); } - - public boolean onMenuItemSelected(int featureId, MenuItem item) { - if (item.getIntent() == null) { - return super.onMenuItemSelected(featureId, item); - } else { - Utilities.startActivityForResultSafely( - this, item.getIntent(), PICK_WALLPAPER_THIRD_PARTY_ACTIVITY); - return true; - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER); - final PackageManager pm = getPackageManager(); - final List apps = - pm.queryIntentActivities(pickWallpaperIntent, 0); - - SubMenu sub = menu.addSubMenu("Other\u2026"); // TODO: what's the better way to do this? - sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - - - // Get list of image picker intents - Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT); - pickImageIntent.setType("image/*"); - final List imagePickerActivities = - pm.queryIntentActivities(pickImageIntent, 0); - final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()]; - for (int i = 0; i < imagePickerActivities.size(); i++) { - ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo; - imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name); - } - - outerLoop: - for (ResolveInfo info : apps) { - final ComponentName itemComponentName = - new ComponentName(info.activityInfo.packageName, info.activityInfo.name); - final String itemPackageName = itemComponentName.getPackageName(); - // Exclude anything from our own package, and the old Launcher - if (itemPackageName.equals(getPackageName()) || - itemPackageName.equals("com.android.launcher")) { - continue; - } - // Exclude any package that already responds to the image picker intent - for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) { - if (itemPackageName.equals( - imagePickerActivityInfo.activityInfo.packageName)) { - continue outerLoop; - } - } - MenuItem mi = sub.add(info.loadLabel(pm)); - Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER); - launchIntent.setComponent(itemComponentName); - mi.setIntent(launchIntent); - Drawable icon = info.loadIcon(pm); - if (icon != null) { - mi.setIcon(icon); - } - } - return super.onCreateOptionsMenu(menu); - } - private void findBundledWallpapers() { mBundledWallpaperThumbs = new ArrayList(24); mBundledWallpaperResIds = new ArrayList(24); -- cgit v1.2.3