summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/AppsCustomizePagedView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher2/AppsCustomizePagedView.java')
-rw-r--r--src/com/android/launcher2/AppsCustomizePagedView.java108
1 files changed, 40 insertions, 68 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 8cb169e17..d52c384bd 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -17,7 +17,6 @@
package com.android.launcher2;
import android.animation.AnimatorSet;
-import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
@@ -35,15 +34,12 @@ import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
-import android.graphics.Insets;
-import android.graphics.MaskFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
-import android.graphics.TableMaskFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
@@ -60,17 +56,16 @@ import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.GridLayout;
import android.widget.ImageView;
-import android.widget.LinearLayout;
import android.widget.Toast;
import com.android.launcher.R;
import com.android.launcher2.DropTarget.DragObject;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import java.lang.ref.WeakReference;
/**
* A simple callback interface which also provides the results of the task.
@@ -233,7 +228,7 @@ class RectCache extends WeakReferenceThreadLocal<Rect> {
* The Apps/Customize page that displays all the applications, widgets, and shortcuts.
*/
public class AppsCustomizePagedView extends PagedViewWithDraggableItems implements
- AllAppsView, View.OnClickListener, View.OnKeyListener, DragSource,
+ View.OnClickListener, View.OnKeyListener, DragSource,
PagedViewIcon.PressedCallback, PagedViewWidget.ShortPressListener,
LauncherTransitionable {
static final String TAG = "AppsCustomizePagedView";
@@ -267,7 +262,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Caching
private Canvas mCanvas;
- private Drawable mDefaultWidgetBackground;
private IconCache mIconCache;
// Dimens
@@ -306,6 +300,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
PendingAddWidgetInfo mCreateWidgetInfo = null;
private boolean mDraggingWidget = false;
+ private Toast mWidgetInstructionToast;
+
// Deferral of loading widget previews during launcher transitions
private boolean mInTransition;
private ArrayList<AsyncTaskPageData> mDeferredSyncWidgetPageItems =
@@ -336,7 +332,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Save the default widget preview background
Resources resources = context.getResources();
- mDefaultWidgetBackground = resources.getDrawable(R.drawable.default_widget_preview_holo);
mAppIconSize = resources.getDimensionPixelSize(R.dimen.app_icon_size);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0);
@@ -528,25 +523,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
- public void onPackagesUpdated(boolean immediate) {
- if (immediate) {
- updatePackages();
- } else {
- // TODO: this isn't ideal, but we actually need to delay here. This call is triggered
- // by a broadcast receiver, and in order for it to work correctly, we need to know that
- // the AppWidgetService has already received and processed the same broadcast. Since there
- // is no guarantee about ordering of broadcast receipt, we just delay here. This is a
- // workaround until we add a callback from AppWidgetService to AppWidgetHost when widget
- // packages are added, updated or removed.
- postDelayed(new Runnable() {
- public void run() {
- updatePackages();
- }
- }, 1500);
- }
- }
-
- public void updatePackages() {
+ public void onPackagesUpdated() {
// Get the list of widgets and shortcuts
mWidgets.clear();
List<AppWidgetProviderInfo> widgets =
@@ -602,16 +579,20 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
} else if (v instanceof PagedViewWidget) {
// Let the user know that they have to long press to add a widget
- Toast.makeText(getContext(), R.string.long_press_widget_to_add,
- Toast.LENGTH_SHORT).show();
+ if (mWidgetInstructionToast != null) {
+ mWidgetInstructionToast.cancel();
+ }
+ mWidgetInstructionToast = Toast.makeText(getContext(),R.string.long_press_widget_to_add,
+ Toast.LENGTH_SHORT);
+ mWidgetInstructionToast.show();
// Create a little animation to show that the widget can move
float offsetY = getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY);
final ImageView p = (ImageView) v.findViewById(R.id.widget_preview);
- AnimatorSet bounce = new AnimatorSet();
- ValueAnimator tyuAnim = ObjectAnimator.ofFloat(p, "translationY", offsetY);
+ AnimatorSet bounce = LauncherAnimUtils.createAnimatorSet();
+ ValueAnimator tyuAnim = LauncherAnimUtils.ofFloat(p, "translationY", offsetY);
tyuAnim.setDuration(125);
- ValueAnimator tydAnim = ObjectAnimator.ofFloat(p, "translationY", 0f);
+ ValueAnimator tydAnim = LauncherAnimUtils.ofFloat(p, "translationY", 0f);
tydAnim.setDuration(100);
bounce.play(tyuAnim).before(tydAnim);
bounce.setInterpolator(new AccelerateInterpolator());
@@ -797,24 +778,17 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
createItemInfo.spanX = createItemInfo.spanY = 1;
}
- // We use a custom alpha clip table for the default widget previews
- Paint alphaClipPaint = null;
- if (createItemInfo instanceof PendingAddWidgetInfo) {
- if (((PendingAddWidgetInfo) createItemInfo).previewImage != 0) {
- MaskFilter alphaClipTable = TableMaskFilter.CreateClipTable(0, 255);
- alphaClipPaint = new Paint();
- alphaClipPaint.setMaskFilter(alphaClipTable);
- }
- }
+ // Don't clip alpha values for the drag outline if we're using the default widget preview
+ boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo &&
+ (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));
// Save the preview for the outline generation, then dim the preview
outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(),
false);
// Start the drag
- alphaClipPaint = null;
mLauncher.lockScreenOrientation();
- mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, alphaClipPaint);
+ mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha);
mDragController.startDrag(image, preview, this, createItemInfo,
DragController.DRAG_ACTION_COPY, null, scale);
outline.recycle();
@@ -1244,7 +1218,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
- float scaleSize = scaledIconWidth / (float) mAppIconSize;
renderDrawableToBitmap(
icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
@@ -1332,7 +1305,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
(int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2);
if (iconId > 0)
icon = mIconCache.getFullResIcon(packageName, iconId);
- Resources resources = mLauncher.getResources();
if (icon != null) {
renderDrawableToBitmap(icon, defaultPreview, hoffset,
yoffset, (int) (mAppIconSize * iconScale),
@@ -1692,23 +1664,10 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
/*
* AllAppsView implementation
*/
- @Override
public void setup(Launcher launcher, DragController dragController) {
mLauncher = launcher;
mDragController = dragController;
}
- @Override
- public void zoom(float zoom, boolean animate) {
- // TODO-APPS_CUSTOMIZE: Call back to mLauncher.zoomed()
- }
- @Override
- public boolean isVisible() {
- return (getVisibility() == VISIBLE);
- }
- @Override
- public boolean isAnimating() {
- return false;
- }
/**
* We should call thise method whenever the core data changes (mApps, mWidgets) so that we can
@@ -1727,7 +1686,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
}
- @Override
public void setApps(ArrayList<ApplicationInfo> list) {
mApps = list;
Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
@@ -1745,7 +1703,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
}
}
- @Override
public void addApps(ArrayList<ApplicationInfo> list) {
addAppsWithoutInvalidate(list);
updatePageCounts();
@@ -1762,6 +1719,16 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
return -1;
}
+ private int findAppByPackage(List<ApplicationInfo> list, String packageName) {
+ int length = list.size();
+ for (int i = 0; i < length; ++i) {
+ ApplicationInfo info = list.get(i);
+ if (ItemInfo.getPackageName(info.intent).equals(packageName)) {
+ return i;
+ }
+ }
+ return -1;
+ }
private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
// loop through all the apps and remove apps that have the same component
int length = list.size();
@@ -1773,13 +1740,21 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
}
}
- @Override
- public void removeApps(ArrayList<ApplicationInfo> list) {
- removeAppsWithoutInvalidate(list);
+ private void removeAppsWithPackageNameWithoutInvalidate(ArrayList<String> packageNames) {
+ // loop through all the package names and remove apps that have the same package name
+ for (String pn : packageNames) {
+ int removeIndex = findAppByPackage(mApps, pn);
+ while (removeIndex > -1) {
+ mApps.remove(removeIndex);
+ removeIndex = findAppByPackage(mApps, pn);
+ }
+ }
+ }
+ public void removeApps(ArrayList<String> packageNames) {
+ removeAppsWithPackageNameWithoutInvalidate(packageNames);
updatePageCounts();
invalidateOnDataChange();
}
- @Override
public void updateApps(ArrayList<ApplicationInfo> list) {
// We remove and re-add the updated applications list because it's properties may have
// changed (ie. the title), and this will ensure that the items will be in their proper
@@ -1790,7 +1765,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
invalidateOnDataChange();
}
- @Override
public void reset() {
// If we have reset, then we should not continue to restore the previous state
mSaveInstanceStateItemIndex = -1;
@@ -1812,7 +1786,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
return (AppsCustomizeTabHost) mLauncher.findViewById(R.id.apps_customize_pane);
}
- @Override
public void dumpState() {
// TODO: Dump information related to current list of Applications, Widgets, etc.
ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
@@ -1837,7 +1810,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
}
}
- @Override
public void surrender() {
// TODO: If we are in the middle of any process (ie. for holographic outlines, etc) we
// should stop this now.