summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2011-05-12 10:40:56 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-05-12 10:40:56 -0700
commit70a10240a9136146f60f07ebfbda9ffd7c955ab3 (patch)
treecfa5ec3b2bb64c13c354a119e231f51db49c8151 /src
parent67962007bfc2bd74758b9df797bfced71d498d55 (diff)
parent46af2e89164b391b7a0049c6ce9048a2b7a7f644 (diff)
downloadandroid_packages_apps_Trebuchet-70a10240a9136146f60f07ebfbda9ffd7c955ab3.tar.gz
android_packages_apps_Trebuchet-70a10240a9136146f60f07ebfbda9ffd7c955ab3.tar.bz2
android_packages_apps_Trebuchet-70a10240a9136146f60f07ebfbda9ffd7c955ab3.zip
Merge "Adding Wallpapers tab."
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/AppsCustomizePagedView.java260
-rw-r--r--src/com/android/launcher2/AppsCustomizeTabHost.java8
-rw-r--r--src/com/android/launcher2/PagedViewWidget.java6
3 files changed, 240 insertions, 34 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 0c4867cf1..5173672da 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -20,19 +20,24 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.xmlpull.v1.XmlPullParser;
+
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
+import android.app.WallpaperManager;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
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.content.res.Resources;
import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
@@ -41,15 +46,15 @@ import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.LruCache;
-import android.view.Gravity;
+import android.util.Slog;
+import android.util.TypedValue;
+import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
-import android.widget.FrameLayout;
import android.widget.ImageView;
-import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.launcher.R;
@@ -63,7 +68,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
*/
public enum ContentType {
Applications,
- Widgets
+ Widgets,
+ Wallpapers
}
// Refs
@@ -76,6 +82,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
private ContentType mContentType;
private ArrayList<ApplicationInfo> mApps;
private List<Object> mWidgets;
+ private List<ResolveInfo> mWallpapers;
// Caching
private Drawable mDefaultWidgetBackground;
@@ -86,8 +93,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Dimens
private int mContentWidth;
private int mMaxWidgetSpan, mMinWidgetSpan;
- private int mWidgetCellWidthGap, mWidgetCellHeightGap;
+ private int mCellWidthGap, mCellHeightGap;
private int mWidgetCountX, mWidgetCountY;
+ private int mWallpaperCountX, mWallpaperCountY;
private final int mWidgetPreviewIconPaddedDimension;
private final float sWidgetPreviewIconPaddingPercentage = 0.25f;
private PagedViewCellLayout mWidgetSpacingLayout;
@@ -104,6 +112,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
mContentType = ContentType.Applications;
mApps = new ArrayList<ApplicationInfo>();
mWidgets = new ArrayList<Object>();
+ mWallpapers = new ArrayList<ResolveInfo>();
mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache();
mWidgetPreviewCache = new LruCache<Object, Bitmap>(sWidgetPreviewCacheSize) {
protected int sizeOf(Object key, Bitmap value) {
@@ -120,12 +129,14 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
a.recycle();
a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0);
- mWidgetCellWidthGap =
+ mCellWidthGap =
a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellWidthGap, 10);
- mWidgetCellHeightGap =
+ mCellHeightGap =
a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellHeightGap, 10);
mWidgetCountX = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountX, 2);
mWidgetCountY = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountY, 2);
+ mWallpaperCountX = a.getInt(R.styleable.AppsCustomizePagedView_wallpaperCountX, 2);
+ mWallpaperCountY = a.getInt(R.styleable.AppsCustomizePagedView_wallpaperCountY, 2);
a.recycle();
// Create a dummy page that we can use to approximate the cell dimensions of widgets and
@@ -164,6 +175,13 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
mWidgets.addAll(mPackageManager.queryIntentActivities(shortcutsIntent, 0));
Collections.sort(mWidgets,
new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
+
+ // Get the list of wallpapers
+ Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
+ mWallpapers = mPackageManager.queryIntentActivities(wallpapersIntent,
+ PackageManager.GET_META_DATA);
+ Collections.sort(mWallpapers,
+ new LauncherModel.ShortcutNameComparator(mPackageManager));
}
/**
@@ -275,30 +293,47 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
});
} else if (v instanceof PagedViewWidget) {
- Workspace w = mLauncher.getWorkspace();
- int currentWorkspaceScreen = mLauncher.getCurrentWorkspaceScreen();
- final CellLayout cl = (CellLayout) w.getChildAt(currentWorkspaceScreen);
- final View dragView = v.findViewById(R.id.widget_preview);
- final ItemInfo itemInfo = (ItemInfo) v.getTag();
- animateClickFeedback(v, new Runnable() {
- @Override
- public void run() {
- cl.calculateSpans(itemInfo);
- if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) {
- if (LauncherApplication.isScreenXLarge()) {
- animateItemOntoScreen(dragView, cl, itemInfo);
+ final ResolveInfo info = (ResolveInfo) v.getTag();
+ if (mWallpapers.contains(info)) {
+ // Start the wallpaper picker
+ animateClickFeedback(v, new Runnable() {
+ @Override
+ public void run() {
+ // add the shortcut
+ Intent createWallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
+ ComponentName name = new ComponentName(info.activityInfo.packageName,
+ info.activityInfo.name);
+ createWallpapersIntent.setComponent(name);
+ mLauncher.processWallpaper(createWallpapersIntent);
+ }
+ });
+ } else {
+ // Add the widget to the current workspace screen
+ Workspace w = mLauncher.getWorkspace();
+ int currentWorkspaceScreen = mLauncher.getCurrentWorkspaceScreen();
+ final CellLayout cl = (CellLayout) w.getChildAt(currentWorkspaceScreen);
+ final View dragView = v.findViewById(R.id.widget_preview);
+ final ItemInfo itemInfo = (ItemInfo) v.getTag();
+ animateClickFeedback(v, new Runnable() {
+ @Override
+ public void run() {
+ cl.calculateSpans(itemInfo);
+ if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) {
+ if (LauncherApplication.isScreenXLarge()) {
+ animateItemOntoScreen(dragView, cl, itemInfo);
+ } else {
+ mLauncher.addExternalItemToScreen(itemInfo, cl);
+ itemInfo.dropPos = null;
+ }
+
+ // Hide the pane so we can see the workspace we dropped on
+ mLauncher.showWorkspace(true);
} else {
- mLauncher.addExternalItemToScreen(itemInfo, cl);
- itemInfo.dropPos = null;
+ mLauncher.showOutOfSpaceMessage();
}
-
- // Hide the pane so we can see the workspace we dropped on
- mLauncher.showWorkspace(true);
- } else {
- mLauncher.showOutOfSpaceMessage();
}
- }
- });
+ });
+ }
}
}
@@ -692,9 +727,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
int numWidgetsPerPage = mWidgetCountX * mWidgetCountY;
int offset = page * numWidgetsPerPage;
int cellWidth = ((mWidgetSpacingLayout.getContentWidth() - mPageLayoutWidthGap
- - ((mWidgetCountX - 1) * mWidgetCellWidthGap)) / mWidgetCountX);
+ - ((mWidgetCountX - 1) * mCellWidthGap)) / mWidgetCountX);
int cellHeight = ((mWidgetSpacingLayout.getContentHeight() - mPageLayoutHeightGap
- - ((mWidgetCountY - 1) * mWidgetCellHeightGap)) / mWidgetCountY);
+ - ((mWidgetCountY - 1) * mCellHeightGap)) / mWidgetCountY);
for (int i = 0; i < Math.min(numWidgetsPerPage, mWidgets.size() - offset); ++i) {
Object rawInfo = mWidgets.get(offset + i);
PendingAddItemInfo createItemInfo = null;
@@ -730,11 +765,166 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
int iy = i / mWidgetCountX;
PagedViewGridLayout.LayoutParams lp = new PagedViewGridLayout.LayoutParams(cellWidth,
cellHeight);
- lp.leftMargin = (ix * cellWidth) + (ix * mWidgetCellWidthGap);
- lp.topMargin = (iy * cellHeight) + (iy * mWidgetCellHeightGap);
+ lp.leftMargin = (ix * cellWidth) + (ix * mCellWidthGap);
+ lp.topMargin = (iy * cellHeight) + (iy * mCellHeightGap);
+ layout.addView(widget, lp);
+ }
+ }
+
+ /*
+ * This method fetches an xml file specified in the manifest identified by
+ * WallpaperManager.WALLPAPER_PREVIEW_META_DATA). The xml file specifies
+ * an image which will be used as the wallpaper preview for an activity
+ * which responds to ACTION_SET_WALLPAPER. This image is returned and used
+ * in the customize drawer.
+ */
+ private Drawable parseWallpaperPreviewXml(ResolveInfo ri) {
+ ActivityInfo activityInfo = ri.activityInfo;
+ XmlResourceParser parser = null;
+ ComponentName component = new ComponentName(ri.activityInfo.packageName,
+ ri.activityInfo.name);
+ try {
+ parser = activityInfo.loadXmlMetaData(mPackageManager,
+ WallpaperManager.WALLPAPER_PREVIEW_META_DATA);
+ if (parser == null) {
+ Slog.w(LOG_TAG, "No " + WallpaperManager.WALLPAPER_PREVIEW_META_DATA
+ + " meta-data for " + "wallpaper provider '" + component + '\'');
+ return null;
+ }
+
+ AttributeSet attrs = Xml.asAttributeSet(parser);
+
+ int type;
+ while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+ && type != XmlPullParser.START_TAG) {
+ // drain whitespace, comments, etc.
+ }
+
+ String nodeName = parser.getName();
+ if (!"wallpaper-preview".equals(nodeName)) {
+ Slog.w(LOG_TAG, "Meta-data does not start with wallpaper-preview tag for "
+ + "wallpaper provider '" + component + '\'');
+ return null;
+ }
+
+ // If metaData was null, we would have returned earlier when getting
+ // the parser No need to do the check here
+ Resources res = mPackageManager.getResourcesForApplication(
+ activityInfo.applicationInfo);
+
+ TypedArray sa = res.obtainAttributes(attrs,
+ com.android.internal.R.styleable.WallpaperPreviewInfo);
+
+ TypedValue value = sa.peekValue(
+ com.android.internal.R.styleable.WallpaperPreviewInfo_staticWallpaperPreview);
+ if (value == null) return null;
+
+ return res.getDrawable(value.resourceId);
+ } catch (Exception e) {
+ Slog.w(LOG_TAG, "XML parsing failed for wallpaper provider '" + component + '\'', e);
+ return null;
+ } finally {
+ if (parser != null) parser.close();
+ }
+ }
+ private FastBitmapDrawable getWallpaperPreview(ResolveInfo info, int cellWidth, int cellHeight){
+ // Return the cached version if necessary
+ Bitmap cachedBitmap = mWidgetPreviewCache.get(info);
+ if (cachedBitmap != null) {
+ return new FastBitmapDrawable(cachedBitmap);
+ }
+
+ // Get the preview
+ Resources resources = getContext().getResources();
+ Drawable wallpaperPreview = parseWallpaperPreviewXml(info);
+ Drawable wallpaperIcon = null;
+ int expectedWidth;
+ int expectedHeight;
+ if (wallpaperPreview != null) {
+ expectedWidth = wallpaperPreview.getIntrinsicWidth();
+ expectedHeight = wallpaperPreview.getIntrinsicHeight();
+ } else {
+ wallpaperPreview = mDefaultWidgetBackground;
+ expectedWidth = expectedHeight = Math.min(cellWidth, cellHeight);
+
+ // Draw the icon in the top left corner
+ String packageName = info.activityInfo.packageName;
+ try {
+ if (info.icon > 0) {
+ wallpaperIcon = mPackageManager.getDrawable(packageName, info.icon, null);
+ }
+ if (wallpaperIcon == null) {
+ wallpaperIcon = resources.getDrawable(R.drawable.ic_launcher_application);
+ }
+ } catch (Resources.NotFoundException e) {}
+ }
+
+ // Create the bitmap
+ Bitmap preview = Bitmap.createBitmap(expectedWidth, expectedHeight, Config.ARGB_8888);
+ renderDrawableToBitmap(wallpaperPreview, preview, 0, 0, expectedWidth, expectedHeight,
+ 1f, 1f);
+ if (wallpaperIcon != null) {
+ int iconSize = resources.getDimensionPixelSize(R.dimen.app_icon_size);
+ int offset = (int) (iconSize * sWidgetPreviewIconPaddingPercentage);
+ renderDrawableToBitmap(wallpaperIcon, preview, offset, offset, iconSize, iconSize,
+ 1f, 1f);
+ }
+
+ FastBitmapDrawable previewDrawable = new FastBitmapDrawable(preview);
+ previewDrawable.setBounds(0, 0, expectedWidth, expectedHeight);
+ mWidgetPreviewCache.put(info, preview);
+ return previewDrawable;
+ }
+ /*
+ * Wallpapers PagedView implementation
+ */
+ public void syncWallpaperPages() {
+ // Ensure that we have the right number of pages
+ Context context = getContext();
+ int numWidgetsPerPage = mWallpaperCountX * mWallpaperCountY;
+ int numPages = (int) Math.ceil(mWallpapers.size() / (float) numWidgetsPerPage);
+ for (int i = 0; i < numPages; ++i) {
+ PagedViewGridLayout layout = new PagedViewGridLayout(context, mWallpaperCountX,
+ mWallpaperCountY);
+ setupPage(layout);
+ addView(layout);
+ }
+ }
+ public void syncWallpaperPageItems(int page) {
+ PagedViewGridLayout layout = (PagedViewGridLayout) getChildAt(page);
+ layout.removeAllViews();
+
+ // Calculate the dimensions of each cell we are giving to each widget
+ int numWidgetsPerPage = mWallpaperCountX * mWallpaperCountY;
+ int offset = page * numWidgetsPerPage;
+ int cellWidth = ((mWidgetSpacingLayout.getContentWidth() - mPageLayoutWidthGap
+ - ((mWallpaperCountX - 1) * mCellWidthGap)) / mWallpaperCountX);
+ int cellHeight = ((mWidgetSpacingLayout.getContentHeight() - mPageLayoutHeightGap
+ - ((mWallpaperCountY - 1) * mCellHeightGap)) / mWallpaperCountY);
+ for (int i = 0; i < Math.min(numWidgetsPerPage, mWallpapers.size() - offset); ++i) {
+ ResolveInfo info = mWallpapers.get(offset + i);
+ PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate(
+ R.layout.apps_customize_wallpaper, layout, false);
+
+ // Fill in the shortcuts information
+ FastBitmapDrawable preview = getWallpaperPreview(info, cellWidth, cellHeight);
+ widget.applyFromResolveInfo(mPackageManager, info, preview, null, false);
+ widget.setTag(info);
+ widget.setOnClickListener(this);
+ widget.setOnLongClickListener(this);
+ widget.setOnTouchListener(this);
+
+ // Layout each widget
+ int ix = i % mWallpaperCountX;
+ int iy = i / mWallpaperCountX;
+ PagedViewGridLayout.LayoutParams lp = new PagedViewGridLayout.LayoutParams(cellWidth,
+ cellHeight);
+ lp.leftMargin = (ix * cellWidth) + (ix * mCellWidthGap);
+ lp.topMargin = (iy * cellHeight) + (iy * mCellHeightGap);
layout.addView(widget, lp);
}
}
+
@Override
public void syncPages() {
removeAllViews();
@@ -745,6 +935,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
case Widgets:
syncWidgetPages();
break;
+ case Wallpapers:
+ syncWallpaperPages();
+ break;
}
}
@Override
@@ -756,6 +949,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
case Widgets:
syncWidgetPageItems(page);
break;
+ case Wallpapers:
+ syncWallpaperPageItems(page);
+ break;
}
}
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index 15920c34a..e2d21b6cb 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -33,6 +33,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
private static final String APPS_TAB_TAG = "APPS";
private static final String WIDGETS_TAB_TAG = "WIDGETS";
+ private static final String WALLPAPERS_TAB_TAG = "WALLPAPERS";
private final LayoutInflater mLayoutInflater;
@@ -70,6 +71,9 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
tabView.setText(mContext.getString(R.string.widgets_tab_label));
addTab(newTabSpec(WIDGETS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
+ tabView = (TextView) mLayoutInflater.inflate(R.layout.tab_widget_indicator, tabs, false);
+ tabView.setText(mContext.getString(R.string.wallpapers_tab_label));
+ addTab(newTabSpec(WALLPAPERS_TAB_TAG).setIndicator(tabView).setContent(contentFactory));
setOnTabChangedListener(this);
// Set the width of the tab bar to match the content (for now)
@@ -91,6 +95,8 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
return AppsCustomizePagedView.ContentType.Applications;
} else if (tag.equals(WIDGETS_TAB_TAG)) {
return AppsCustomizePagedView.ContentType.Widgets;
+ } else if (tag.equals(WALLPAPERS_TAB_TAG)) {
+ return AppsCustomizePagedView.ContentType.Wallpapers;
}
return AppsCustomizePagedView.ContentType.Applications;
}
@@ -103,6 +109,8 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
return APPS_TAB_TAG;
} else if (type == AppsCustomizePagedView.ContentType.Widgets) {
return WIDGETS_TAB_TAG;
+ } else if (type == AppsCustomizePagedView.ContentType.Wallpapers) {
+ return WALLPAPERS_TAB_TAG;
}
return APPS_TAB_TAG;
}
diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java
index 41473c336..6492888ce 100644
--- a/src/com/android/launcher2/PagedViewWidget.java
+++ b/src/com/android/launcher2/PagedViewWidget.java
@@ -211,8 +211,10 @@ public class PagedViewWidget extends LinearLayout implements Checkable {
name.setText(info.loadLabel(pm));
name.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
final TextView dims = (TextView) findViewById(R.id.widget_dims);
- dims.setText(String.format(mDimensionsFormatString, 1, 1));
- dims.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+ if (dims != null) {
+ dims.setText(String.format(mDimensionsFormatString, 1, 1));
+ dims.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+ }
if (createHolographicOutline) {
mIconCache = cache;