Locking pressed state for AllApps icons.

- Setting workaround for transition state bug until b/5897600 is fixed.

Change-Id: Icb29a4cd7bfaf527a9db5b853e7fb24c63b58b30
This commit is contained in:
Winson Chung
2012-01-23 14:45:13 -08:00
parent 28c1854896
commit e4e506660b
4 changed files with 66 additions and 5 deletions
@@ -166,7 +166,8 @@ class AppsCustomizeAsyncTask extends AsyncTask<AsyncTaskPageData, Void, AsyncTas
* The Apps/Customize page that displays all the applications, widgets, and shortcuts.
*/
public class AppsCustomizePagedView extends PagedViewWithDraggableItems implements
AllAppsView, View.OnClickListener, View.OnKeyListener, DragSource {
AllAppsView, View.OnClickListener, View.OnKeyListener, DragSource,
PagedViewIcon.PressedCallback {
static final String LOG_TAG = "AppsCustomizePagedView";
/**
@@ -185,6 +186,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Save and Restore
private int mSaveInstanceStateItemIndex = -1;
private PagedViewIcon mPressedIcon;
// Content
private ArrayList<ApplicationInfo> mApps;
@@ -593,6 +595,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
if (!super.beginDragging(v)) return false;
// Reset the alpha on the dragged icon before we drag
resetDrawableState();
// Go into spring loaded mode (must happen before we startDrag())
mLauncher.enterSpringLoadedDragMode();
@@ -751,7 +756,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
ApplicationInfo info = mApps.get(i);
PagedViewIcon icon = (PagedViewIcon) mLayoutInflater.inflate(
R.layout.apps_customize_application, layout, false);
icon.applyFromApplicationInfo(info, true);
icon.applyFromApplicationInfo(info, true, this);
icon.setOnClickListener(this);
icon.setOnLongClickListener(this);
icon.setOnTouchListener(this);
@@ -1427,6 +1432,22 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
cancelAllTasks();
}
@Override
public void iconPressed(PagedViewIcon icon) {
// Reset the previously pressed icon and store a reference to the pressed icon so that
// we can reset it on return to Launcher (in Launcher.onResume())
if (mPressedIcon != null) {
mPressedIcon.resetDrawableState();
}
mPressedIcon = icon;
}
public void resetDrawableState() {
if (mPressedIcon != null) {
mPressedIcon.resetDrawableState();
mPressedIcon = null;
}
}
/*
* We load an extra page on each side to prevent flashes from scrolling and loading of the
+8
View File
@@ -561,9 +561,17 @@ public final class Launcher extends Activity
mRestoring = false;
mOnResumeNeedsLoad = false;
}
// Reset the pressed state of icons that were locked in the press state while activities
// were launching
if (mWaitingForResume != null) {
// Resets the previous workspace icon press state
mWaitingForResume.setStayPressed(false);
}
if (mAppsCustomizeContent != null) {
// Resets the previous all apps icon press state
mAppsCustomizeContent.resetDrawableState();
}
// When we resume Launcher, a different Activity might be responsible for the app
// market intent, so refresh the icon
updateAppMarketIcon();
+34 -2
View File
@@ -26,7 +26,16 @@ import android.widget.TextView;
* drawables on the top).
*/
public class PagedViewIcon extends TextView {
/** A simple callback interface to allow a PagedViewIcon to notify when it has been pressed */
public static interface PressedCallback {
void iconPressed(PagedViewIcon icon);
}
private static final String TAG = "PagedViewIcon";
private static final float PRESS_ALPHA = 0.4f;
private PagedViewIcon.PressedCallback mPressedCallback;
private boolean mResetDrawableState = false;
private Bitmap mIcon;
@@ -42,15 +51,38 @@ public class PagedViewIcon extends TextView {
super(context, attrs, defStyle);
}
public void applyFromApplicationInfo(ApplicationInfo info, boolean scaleUp) {
public void applyFromApplicationInfo(ApplicationInfo info, boolean scaleUp,
PagedViewIcon.PressedCallback cb) {
mIcon = info.iconBitmap;
mPressedCallback = cb;
setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
setText(info.title);
setTag(info);
}
public void resetDrawableState() {
mResetDrawableState = true;
post(new Runnable() {
@Override
public void run() {
refreshDrawableState();
}
});
}
protected void drawableStateChanged() {
setAlpha(isPressed() ? 0.5f : 1f);
super.drawableStateChanged();
// We keep in the pressed state until resetDrawableState() is called to reset the press
// feedback
if (isPressed()) {
setAlpha(PRESS_ALPHA);
if (mPressedCallback != null) {
mPressedCallback.iconPressed(this);
}
} else if (mResetDrawableState) {
setAlpha(1f);
mResetDrawableState = false;
}
}
}
+1 -1
View File
@@ -231,7 +231,7 @@ public class Workspace extends SmoothPagedView
private float[] mNewBackgroundAlphaMultipliers;
private float[] mNewAlphas;
private float[] mNewRotationYs;
private float mTransitionProgress;
private float mTransitionProgress = 1f;
/**
* Used to inflate the Workspace from XML.