diff options
Diffstat (limited to 'src/com/android/launcher2/CustomizePagedView.java')
-rw-r--r-- | src/com/android/launcher2/CustomizePagedView.java | 188 |
1 files changed, 65 insertions, 123 deletions
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 6aa4c7230..b2a7603b5 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -16,10 +16,6 @@ package com.android.launcher2; -import com.android.launcher.R; - -import org.xmlpull.v1.XmlPullParser; - import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; @@ -43,7 +39,6 @@ import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Bitmap.Config; import android.graphics.drawable.Drawable; -import android.os.AsyncTask; import android.util.AttributeSet; import android.util.Log; import android.util.Slog; @@ -55,7 +50,6 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.View.MeasureSpec; import android.view.animation.DecelerateInterpolator; import android.view.animation.LinearInterpolator; import android.widget.Checkable; @@ -63,6 +57,11 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import com.android.launcher.R; +import com.android.launcher2.DropTarget.DragObject; + +import org.xmlpull.v1.XmlPullParser; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -100,10 +99,6 @@ public class CustomizePagedView extends PagedViewWithDraggableItems // The max dimensions for the ImageView we use for displaying a widget private int mMaxWidgetWidth; - // The min and max dimensions for the bitmap that is used for a widget preview - private int mMinWidgetPreviewDim; - private int mMaxWidgetPreviewDim; - // The max number of widget cells to take a "page" of widgets private int mMaxWidgetsCellHSpan; @@ -157,7 +152,6 @@ public class CustomizePagedView extends PagedViewWithDraggableItems private AllAppsPagedView mAllAppsPagedView; private boolean mWaitingToInitPages = true; - private boolean mWaitingToDetermineRowsAndColumns = true; public CustomizePagedView(Context context) { this(context, null, 0); @@ -229,8 +223,8 @@ public class CustomizePagedView extends PagedViewWithDraggableItems @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - if (mWaitingToDetermineRowsAndColumns) { - mWaitingToDetermineRowsAndColumns = false; + if (mWaitingToInitPages) { + mWaitingToInitPages = false; postInvalidatePageData(false); } super.onLayout(changed, left, top, right, bottom); @@ -256,7 +250,6 @@ public class CustomizePagedView extends PagedViewWithDraggableItems // Update the widgets/shortcuts to reflect changes in the set of available apps mPageViewIconCache.retainAllApps(list); - mWaitingToInitPages = false; invalidatePageData(); } @@ -353,13 +346,8 @@ public class CustomizePagedView extends PagedViewWithDraggableItems } }); - Comparator<ResolveInfo> resolveInfoComparator = new Comparator<ResolveInfo>() { - @Override - public int compare(ResolveInfo object1, ResolveInfo object2) { - return object1.loadLabel(mPackageManager).toString().compareTo( - object2.loadLabel(mPackageManager).toString()); - } - }; + LauncherModel.ShortcutNameComparator resolveInfoComparator = + new LauncherModel.ShortcutNameComparator(mPackageManager); // get the list of shortcuts Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); @@ -414,7 +402,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems } } - public void onDropCompleted(View target, Object dragInfo, boolean success) { + public void onDropCompleted(View target, DragObject d, boolean success) { final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer); // Create a view, identical to the drag view, that is only used for animating the @@ -425,7 +413,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems if (success) { resetCheckedItem(true); - animateDropOntoScreen(animView, (ItemInfo) dragInfo, DROP_ANIM_DURATION, 0); + animateDropOntoScreen(animView, (ItemInfo) d.dragInfo, DROP_ANIM_DURATION, 0); } else { // Animate the icon/widget back to its original position animateIntoPosition(animView, mDragViewOrigin[0], mDragViewOrigin[1], new Runnable() { @@ -540,8 +528,6 @@ public class CustomizePagedView extends PagedViewWithDraggableItems @Override public void onClick(final View v) { - // Return early if this is not initiated from a touch - if (!v.isInTouchMode()) return; // Return early if we are still animating the pages if (mNextPage != INVALID_PAGE) return; @@ -868,14 +854,13 @@ public class CustomizePagedView extends PagedViewWithDraggableItems /** * This method will extract the preview image specified by the widget developer (if it exists), * otherwise, it will try to generate a default image preview with the widget's package icon. - * This method must be safe to call from a background thread - * @return the Bitmap that will be wrapped in a FastBitmapDrawable and used and sized in the - * ImageView to represent the widget + * @return the drawable that will be used and sized in the ImageView to represent the widget */ - private Bitmap getWidgetPreview(AppWidgetProviderInfo info) { + private FastBitmapDrawable getWidgetPreview(AppWidgetProviderInfo info) { final PackageManager packageManager = mPackageManager; String packageName = info.provider.getPackageName(); Drawable drawable = null; + FastBitmapDrawable newDrawable = null; if (info.previewImage != 0) { drawable = packageManager.getDrawable(packageName, info.previewImage, null); if (drawable == null) { @@ -885,14 +870,14 @@ public class CustomizePagedView extends PagedViewWithDraggableItems } // If we don't have a preview image, create a default one + final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1); + final int maxDim = mWorkspaceWidgetLayout.estimateCellWidth(3); if (drawable == null) { Resources resources = mLauncher.getResources(); // Create a new bitmap to hold the widget preview - int width = (int) (Math.max(mMinWidgetPreviewDim, - Math.min(mMaxWidgetPreviewDim, info.minWidth)) * sScaleFactor); - int height = (int) (Math.max(mMinWidgetPreviewDim, - Math.min(mMaxWidgetPreviewDim, info.minHeight)) * sScaleFactor); + int width = (int) (Math.max(minDim, Math.min(maxDim, info.minWidth)) * sScaleFactor); + int height = (int) (Math.max(minDim, Math.min(maxDim, info.minHeight)) * sScaleFactor); final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); final Drawable background = resources.getDrawable(R.drawable.default_widget_preview); renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f); @@ -907,23 +892,23 @@ public class CustomizePagedView extends PagedViewWithDraggableItems icon = resources.getDrawable(R.drawable.ic_launcher_application); } - final int iconSize = mMinWidgetPreviewDim / 2; + final int iconSize = minDim / 2; final int offset = iconSize / 4; renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f); } catch (Resources.NotFoundException e) { // if we can't find the icon, then just don't draw it } - return bitmap; + newDrawable = new FastBitmapDrawable(bitmap); } else { // Scale down the preview if necessary final float imageWidth = drawable.getIntrinsicWidth(); final float imageHeight = drawable.getIntrinsicHeight(); final float aspect = (float) imageWidth / imageHeight; - final int scaledWidth = (int) (Math.max(mMinWidgetPreviewDim, - Math.min(mMaxWidgetPreviewDim, imageWidth)) * sScaleFactor); - final int scaledHeight = (int) (Math.max(mMinWidgetPreviewDim, - Math.min(mMaxWidgetPreviewDim, imageHeight)) * sScaleFactor); + final int scaledWidth = + (int) (Math.max(minDim, Math.min(maxDim, imageWidth)) * sScaleFactor); + final int scaledHeight = + (int) (Math.max(minDim, Math.min(maxDim, imageHeight)) * sScaleFactor); int width; int height; if (aspect >= 1.0f) { @@ -937,8 +922,11 @@ public class CustomizePagedView extends PagedViewWithDraggableItems final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); renderDrawableToBitmap(drawable, bitmap, 0, 0, width, height, 1.0f, 1.0f); - return bitmap; + newDrawable = new FastBitmapDrawable(bitmap); } + newDrawable.setBounds(0, 0, newDrawable.getIntrinsicWidth(), + newDrawable.getIntrinsicHeight()); + return newDrawable; } private void setupPage(PagedViewCellLayout layout) { @@ -953,8 +941,6 @@ public class CustomizePagedView extends PagedViewWithDraggableItems mWorkspaceWidgetLayout.setPadding(20, 10, 20, 0); mMaxWidgetWidth = mWorkspaceWidgetLayout.estimateCellWidth(sMaxWidgetCellHSpan); - mMinWidgetPreviewDim = mWorkspaceWidgetLayout.estimateCellWidth(1); - mMaxWidgetPreviewDim = mWorkspaceWidgetLayout.estimateCellWidth(3); } private void syncWidgetPages() { @@ -964,90 +950,43 @@ public class CustomizePagedView extends PagedViewWithDraggableItems removeAllViews(); int numPages = relayoutWidgets(); for (int i = 0; i < numPages; ++i) { - PagedViewExtendedLayout layout = new PagedViewExtendedLayout(getContext()); + LinearLayout layout = new PagedViewExtendedLayout(getContext()); layout.setGravity(Gravity.CENTER_HORIZONTAL); layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight, mPageLayoutPaddingBottom); - if (i < (numPages - 1)) { - layout.setHasFixedWidth(true); - layout.setMinimumWidth(mMinPageWidth); - } + addView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); } } - private static class AppWidgetsPageToSync { - public AppWidgetsPageToSync( - LinearLayout layout, ArrayList<AppWidgetProviderInfo> appWidgets) { - mLayout = layout; - mAppWidgets = (ArrayList<AppWidgetProviderInfo>) appWidgets.clone(); - mAppWidgetBitmaps = new ArrayList<Bitmap>(appWidgets.size()); - } - public int mPage; - public LinearLayout mLayout; - public ArrayList<AppWidgetProviderInfo> mAppWidgets; - public ArrayList<Bitmap> mAppWidgetBitmaps; - } - private void syncWidgetPageItems(int page) { + // ensure that we have the right number of items on the pages LinearLayout layout = (LinearLayout) getChildAt(page); + final ArrayList<AppWidgetProviderInfo> list = mWidgetPages.get(page); + final int count = list.size(); + final int numPages = getPageCount(); layout.removeAllViews(); - AppWidgetsPageToSync pageToSync = - new AppWidgetsPageToSync(layout, mWidgetPages.get(page)); - - // Load the widget previews in the bcakground - new SyncWidgetPageItemsTask().execute(pageToSync); - } - - private class SyncWidgetPageItemsTask extends - AsyncTask<AppWidgetsPageToSync, Void, AppWidgetsPageToSync> { - protected AppWidgetsPageToSync doInBackground(AppWidgetsPageToSync... args) { - if (args.length != 1) { - throw new RuntimeException("Wrong number of args to SyncWidgetPageItemsTask"); - } - AppWidgetsPageToSync pageToSync = args[0]; - - // generating widgetPreviews on more than one thread at a time causes a crash - synchronized(CustomizePagedView.this) { - // Load whatever was not in the cache - int numWidgets = pageToSync.mAppWidgets.size(); - for (int i = 0; i < numWidgets; i++) { - AppWidgetProviderInfo info = pageToSync.mAppWidgets.get(i); - pageToSync.mAppWidgetBitmaps.add(getWidgetPreview(info)); - } - } - return pageToSync; - } + for (int i = 0; i < count; ++i) { + final AppWidgetProviderInfo info = (AppWidgetProviderInfo) list.get(i); + final PendingAddWidgetInfo createItemInfo = new PendingAddWidgetInfo(info, null, null); + final int[] cellSpans = CellLayout.rectToCell(getResources(), info.minWidth, + info.minHeight, null); + final FastBitmapDrawable icon = getWidgetPreview(info); + final boolean createHolographicOutlines = (numPages > 1); - protected void onPostExecute(AppWidgetsPageToSync pageToSync) { - LinearLayout layout = (LinearLayout) pageToSync.mLayout; - final int numPages = getPageCount(); - final int numWidgets = pageToSync.mAppWidgets.size(); - for (int i = 0; i < numWidgets; ++i) { - final AppWidgetProviderInfo info = pageToSync.mAppWidgets.get(i); - final PendingAddWidgetInfo createItemInfo = - new PendingAddWidgetInfo(info, null, null); - final int[] cellSpans = CellLayout.rectToCell(getResources(), info.minWidth, - info.minHeight, null); - - FastBitmapDrawable icon - = new FastBitmapDrawable(pageToSync.mAppWidgetBitmaps.get(i)); - icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); - - PagedViewWidget l = (PagedViewWidget) mInflater.inflate( + PagedViewWidget l = (PagedViewWidget) mInflater.inflate( R.layout.customize_paged_view_widget, layout, false); - l.applyFromAppWidgetProviderInfo(info, icon, mMaxWidgetWidth, cellSpans, - mPageViewIconCache, (numPages > 1)); - l.setTag(createItemInfo); - l.setOnClickListener(CustomizePagedView.this); - l.setOnTouchListener(CustomizePagedView.this); - l.setOnLongClickListener(CustomizePagedView.this); + l.applyFromAppWidgetProviderInfo(info, icon, mMaxWidgetWidth, cellSpans, + mPageViewIconCache, createHolographicOutlines); + l.setTag(createItemInfo); + l.setOnClickListener(this); + l.setOnTouchListener(this); + l.setOnLongClickListener(this); - layout.addView(l); - } + layout.addView(l); } } @@ -1059,14 +998,11 @@ public class CustomizePagedView extends PagedViewWithDraggableItems int numPages = (int) Math.ceil((float) (mWallpaperList.size() * mWallpaperCellHSpan) / mMaxWallpaperCellHSpan); for (int i = 0; i < numPages; ++i) { - PagedViewExtendedLayout layout = new PagedViewExtendedLayout(getContext()); + LinearLayout layout = new PagedViewExtendedLayout(getContext()); layout.setGravity(Gravity.CENTER_HORIZONTAL); layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight, mPageLayoutPaddingBottom); - if (i < (numPages - 1)) { - layout.setHasFixedWidth(true); - layout.setMinimumWidth(mMinPageWidth); - } + addView(layout, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); @@ -1085,11 +1021,12 @@ public class CustomizePagedView extends PagedViewWithDraggableItems for (int i = startIndex; i < endIndex; ++i) { final ResolveInfo info = mWallpaperList.get(i); final FastBitmapDrawable icon = getWallpaperPreview(info); + final boolean createHolographicOutlines = (numPages > 1); PagedViewWidget l = (PagedViewWidget) mInflater.inflate( R.layout.customize_paged_view_wallpaper, layout, false); l.applyFromWallpaperInfo(info, mPackageManager, icon, mMaxWidgetWidth, - mPageViewIconCache, (numPages > 1)); + mPageViewIconCache, createHolographicOutlines); l.setTag(info); l.setOnClickListener(this); @@ -1122,12 +1059,13 @@ public class CustomizePagedView extends PagedViewWithDraggableItems for (int i = startIndex; i < endIndex; ++i) { ResolveInfo info = list.get(i); PendingAddItemInfo createItemInfo = new PendingAddItemInfo(); + final boolean createHolographicOutlines = (numPages > 1); PagedViewIcon icon = (PagedViewIcon) mInflater.inflate( R.layout.customize_paged_view_item, layout, false); icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache, ((LauncherApplication) mLauncher.getApplication()).getIconCache(), - (numPages > 1)); + createHolographicOutlines); switch (mCustomizationType) { case WallpaperCustomization: icon.setOnClickListener(this); @@ -1181,9 +1119,11 @@ public class CustomizePagedView extends PagedViewWithDraggableItems layout.removeAllViewsOnPage(); for (int i = startIndex; i < endIndex; ++i) { final ApplicationInfo info = mApps.get(i); + final boolean createHolographicOutlines = (numPages > 1); PagedViewIcon icon = (PagedViewIcon) mInflater.inflate( R.layout.all_apps_paged_view_application, layout, false); - icon.applyFromApplicationInfo(info, mPageViewIconCache, true, (numPages > 1)); + icon.applyFromApplicationInfo( + info, mPageViewIconCache, true, createHolographicOutlines); icon.setOnClickListener(this); icon.setOnTouchListener(this); icon.setOnLongClickListener(this); @@ -1198,7 +1138,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems @Override protected void invalidatePageData() { - if (mWaitingToDetermineRowsAndColumns || mWaitingToInitPages || mCellCountX <= 0 || mCellCountY <= 0) { + if (mWaitingToInitPages || mCellCountX <= 0 || mCellCountY <= 0) { // We don't know our size yet, which means we haven't calculated cell count x/y; // onMeasure will call us once we figure out our size return; @@ -1248,8 +1188,10 @@ public class CustomizePagedView extends PagedViewWithDraggableItems } // Set a min page width for PagedView layout if we have more than a single page - if (enforceMinimumPagedWidths) { - setMinimumWidthOverride((childCount > 1) ? mMinPageWidth : 0); + if (enforceMinimumPagedWidths && childCount > 1) { + setMinimumWidthOverride(mMinPageWidth); + } else { + resetMinimumWidthOverride(); } // Bound the current page index @@ -1287,11 +1229,11 @@ public class CustomizePagedView extends PagedViewWithDraggableItems @Override protected int getAssociatedLowerPageBound(int page) { - return Math.max(0, page - 2); + return 0; } @Override protected int getAssociatedUpperPageBound(int page) { - return Math.min(page + 2, getChildCount() - 1); + return getChildCount(); } @Override |