Changing AllApps checked visualization, fixing drag offset issue in AllApps/Customize.

- fixing previous change which clobbered pressed/focused state padding

Change-Id: I229d803322554e51bc9c1f15d3687b01b0f6679f
This commit is contained in:
Winson Chung
2010-12-09 18:52:32 -08:00
parent bf54662596
commit cd4bc491c4
8 changed files with 64 additions and 40 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

+20 -12
View File
@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
@@ -246,16 +247,6 @@ public class AllAppsPagedView extends PagedView
return false;
}
if (v instanceof Checkable) {
// In preparation for drag, we always reset the checked grand children regardless of
// what choice mode we are in
resetCheckedGrandchildren();
// Toggle the selection on the dragged app
Checkable c = (Checkable) v;
c.toggle();
}
// Start drag mode after the item is selected
setupDragMode();
@@ -263,13 +254,30 @@ public class AllAppsPagedView extends PagedView
app = new ApplicationInfo(app);
// get icon (top compound drawable, index is 1)
final Drawable icon = ((TextView) v).getCompoundDrawables()[1];
Bitmap b = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
final TextView tv = (TextView) v;
final Drawable icon = tv.getCompoundDrawables()[1];
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.translate((v.getWidth() - icon.getIntrinsicWidth()) / 2, v.getPaddingTop());
icon.draw(c);
// We toggle the checked state _after_ we create the view for the drag in case toggling the
// checked state changes the view's look
if (v instanceof Checkable) {
// In preparation for drag, we always reset the checked grand children regardless of
// what choice mode we are in
resetCheckedGrandchildren();
// Toggle the selection on the dragged app
Checkable checkable = (Checkable) v;
checkable.toggle();
}
// Start the drag
mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
b.recycle();
return true;
}
@@ -24,10 +24,10 @@ import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.TimeInterpolator;
import android.animation.Animator.AnimatorListener;
import android.app.WallpaperManager;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
@@ -41,8 +41,9 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
@@ -571,10 +572,10 @@ public class CustomizePagedView extends PagedView
return super.onTouchEvent(ev);
}
Bitmap drawableToBitmap(Drawable d) {
Bitmap b = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
Bitmap drawableToBitmap(Drawable d, View v) {
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.translate((v.getWidth() - d.getIntrinsicWidth()) / 2, v.getPaddingTop());
d.draw(c);
return b;
}
@@ -595,10 +596,10 @@ public class CustomizePagedView extends PagedView
case WidgetCustomization: {
// Get the widget preview as the drag representation
final LinearLayout l = (LinearLayout) v;
final Drawable icon = ((ImageView) l.findViewById(R.id.widget_preview)).getDrawable();
Bitmap b = drawableToBitmap(icon);
final ImageView i = (ImageView) l.findViewById(R.id.widget_preview);
final Drawable icon = i.getDrawable();
Bitmap b = drawableToBitmap(icon, i);
PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag();
final View dragView = v.findViewById(R.id.widget_preview);
int[] spanXY = CellLayout.rectToCell(
getResources(), createWidgetInfo.minWidth, createWidgetInfo.minHeight, null);
@@ -606,30 +607,35 @@ public class CustomizePagedView extends PagedView
createWidgetInfo.spanY = spanXY[1];
mLauncher.getWorkspace().onDragStartedWithItemSpans(spanXY[0], spanXY[1], b);
mDragController.startDrag(
v, b, this, createWidgetInfo, DragController.DRAG_ACTION_COPY, null);
i, b, this, createWidgetInfo, DragController.DRAG_ACTION_COPY, null);
b.recycle();
return true;
}
case ShortcutCustomization: {
// get icon (top compound drawable, index is 1)
final Drawable icon = ((TextView) v).getCompoundDrawables()[1];
Bitmap b = drawableToBitmap(icon);
final TextView tv = (TextView) v;
final Drawable icon = tv.getCompoundDrawables()[1];
Bitmap b = drawableToBitmap(icon, tv);
PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();
mDragController.startDrag(
v, b, this, createItemInfo, DragController.DRAG_ACTION_COPY, null);
mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
mDragController.startDrag(v, b, this, createItemInfo, DragController.DRAG_ACTION_COPY,
null);
b.recycle();
return true;
}
case ApplicationCustomization: {
// Pick up the application for dropping
// get icon (top compound drawable, index is 1)
final Drawable icon = ((TextView) v).getCompoundDrawables()[1];
Bitmap b = drawableToBitmap(icon);
final TextView tv = (TextView) v;
final Drawable icon = tv.getCompoundDrawables()[1];
Bitmap b = drawableToBitmap(icon, tv);
ApplicationInfo app = (ApplicationInfo) v.getTag();
app = new ApplicationInfo(app);
mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
b.recycle();
return true;
}
}
+19 -10
View File
@@ -16,6 +16,7 @@
package com.android.launcher2;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -28,7 +29,6 @@ import android.os.HandlerThread;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.Checkable;
import android.widget.TextView;
import com.android.launcher.R;
import com.android.launcher2.PagedView.PagedViewIconCache;
@@ -56,6 +56,10 @@ public class PagedViewIcon extends CacheableTextView implements Checkable {
private int mHolographicAlpha;
private boolean mIsChecked;
private ObjectAnimator mCheckedAlphaAnimator;
private final static float sCheckedAlpha = 0.4f;
private final static int sCheckedFadeInDuration = 150;
private final static int sCheckedFadeOutDuration = 200;
// Highlight colors
private int mHoloBlurColor;
@@ -230,19 +234,24 @@ public class PagedViewIcon extends CacheableTextView implements Checkable {
if (mIsChecked != checked) {
mIsChecked = checked;
float alpha;
int duration;
if (mIsChecked) {
mCheckedOutline = Bitmap.createBitmap(mIcon.getWidth(), mIcon.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas checkedOutlineCanvas = new Canvas(mCheckedOutline);
mPaint.setAlpha(255);
checkedOutlineCanvas.drawBitmap(mIcon, 0, 0, mPaint);
sHolographicOutlineHelper.applyThickExpensiveOutlineWithBlur(mCheckedOutline,
checkedOutlineCanvas, mCheckedBlurColor, mCheckedOutlineColor);
alpha = sCheckedAlpha;
duration = sCheckedFadeInDuration;
} else {
invalidateCheckedImage();
alpha = 1.0f;
duration = sCheckedFadeOutDuration;
}
// Initialize the animator
if (mCheckedAlphaAnimator != null) {
mCheckedAlphaAnimator.cancel();
}
mCheckedAlphaAnimator = ObjectAnimator.ofFloat(this, "alpha", alpha);
mCheckedAlphaAnimator.setDuration(duration);
mCheckedAlphaAnimator.start();
invalidate();
}
}
+2 -1
View File
@@ -21,12 +21,12 @@ import java.util.HashSet;
import java.util.List;
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.AlertDialog;
import android.app.WallpaperManager;
@@ -44,6 +44,7 @@ import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;