From faa790c4f55bfe399a8ef259c657be76e9d833dd Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Fri, 2 Sep 2011 17:35:02 -0700 Subject: Fix the pressed state for thumbnails in Recents - pressed state is now in foreground - also, keep drawing pressed drawable on long press Change-Id: I1a2025b5a79a5bfd4aaacf5312d52404fc3361a1 --- .../android/systemui/recent/RecentsCallback.java | 2 +- .../recent/RecentsHorizontalScrollView.java | 4 +-- .../android/systemui/recent/RecentsPanelView.java | 35 ++++++++++++++++++++-- .../systemui/recent/RecentsVerticalScrollView.java | 3 +- 4 files changed, 37 insertions(+), 7 deletions(-) (limited to 'packages/SystemUI/src') diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsCallback.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsCallback.java index e3c4eb7..78050a2 100644 --- a/packages/SystemUI/src/com/android/systemui/recent/RecentsCallback.java +++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsCallback.java @@ -26,7 +26,7 @@ public interface RecentsCallback { void handleOnClick(View selectedView); void handleSwipe(View selectedView); - void handleLongPress(View selectedView, View anchorView); + void handleLongPress(View selectedView, View anchorView, View thumbnailView); void handleShowBackground(boolean show); void dismiss(); diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java index 5c1bbf0..fc03a27 100644 --- a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java +++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java @@ -26,7 +26,6 @@ import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; -import android.view.View.OnClickListener; import android.widget.HorizontalScrollView; import android.widget.LinearLayout; @@ -48,7 +47,8 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView private OnLongClickListener mOnLongClick = new OnLongClickListener() { public boolean onLongClick(View v) { final View anchorView = v.findViewById(R.id.app_description); - mCallback.handleLongPress(v, anchorView); + final View thumbnailView = v.findViewById(R.id.app_thumbnail); + mCallback.handleLongPress(v, anchorView, thumbnailView); return true; } }; diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java index fc33931..43905dd 100644 --- a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java @@ -30,15 +30,14 @@ import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; -import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Shader.TileMode; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.StateListDrawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Handler; @@ -57,6 +56,7 @@ import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.BaseAdapter; +import android.widget.FrameLayout; import android.widget.HorizontalScrollView; import android.widget.ImageView; import android.widget.PopupMenu; @@ -85,6 +85,7 @@ public class RecentsPanelView extends RelativeLayout private View mRecentsGlowView; private ViewGroup mRecentsContainer; private Bitmap mDefaultThumbnailBackground; + private BitmapDrawable mPressedDrawable; private boolean mShowing; private Choreographer mChoreo; @@ -182,6 +183,13 @@ public class RecentsPanelView extends RelativeLayout holder.iconView = (ImageView) convertView.findViewById(R.id.app_icon); holder.labelView = (TextView) convertView.findViewById(R.id.app_label); holder.descriptionView = (TextView) convertView.findViewById(R.id.app_description); + + StateListDrawable thumbnailForegroundDrawable = new StateListDrawable(); + thumbnailForegroundDrawable.addState(new int[] { android.R.attr.state_pressed }, + mPressedDrawable); + thumbnailForegroundDrawable.addState(new int[] { android.R.attr.state_selected }, + mPressedDrawable); + ((FrameLayout)holder.thumbnailView).setForeground(thumbnailForegroundDrawable); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); @@ -339,9 +347,23 @@ public class RecentsPanelView extends RelativeLayout int width = (int) res.getDimension(R.dimen.status_bar_recents_thumbnail_width); int height = (int) res.getDimension(R.dimen.status_bar_recents_thumbnail_height); int color = res.getColor(R.drawable.status_bar_recents_app_thumbnail_background); + + // Render the default thumbnail background mDefaultThumbnailBackground = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(mDefaultThumbnailBackground); c.drawColor(color); + + // Render the pressed state (setting the 9 patch drawable directly causes padding issues) + int bgPadding = (int) res.getDimension(R.dimen.recents_thumbnail_bg_press_padding); + Bitmap pressedOverlay = Bitmap.createBitmap( + width + 2 * bgPadding, height + 2 * bgPadding, Bitmap.Config.ARGB_8888); + c.setBitmap(pressedOverlay); + + Drawable pressedDrawable9Patch = res.getDrawable(R.drawable.recents_thumbnail_bg_press); + pressedDrawable9Patch.getCurrent().setBounds( + 0, 0, pressedOverlay.getWidth(), pressedOverlay.getHeight()); + pressedDrawable9Patch.draw(c); + mPressedDrawable = new BitmapDrawable(res, pressedOverlay); } @Override @@ -715,7 +737,9 @@ public class RecentsPanelView extends RelativeLayout getContext().startActivity(intent); } - public void handleLongPress(final View selectedView, final View anchorView) { + public void handleLongPress( + final View selectedView, final View anchorView, final View thumbnailView) { + thumbnailView.setSelected(true); PopupMenu popup = new PopupMenu(mContext, anchorView == null ? selectedView : anchorView); popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @@ -737,6 +761,11 @@ public class RecentsPanelView extends RelativeLayout return true; } }); + popup.setOnDismissListener(new PopupMenu.OnDismissListener() { + public void onDismiss(PopupMenu menu) { + thumbnailView.setSelected(false); + } + }); popup.show(); } } diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java index 1978d69..b12387a 100644 --- a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java +++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java @@ -46,7 +46,8 @@ public class RecentsVerticalScrollView extends ScrollView implements SwipeHelper private OnLongClickListener mOnLongClick = new OnLongClickListener() { public boolean onLongClick(View v) { final View anchorView = v.findViewById(R.id.app_description); - mCallback.handleLongPress(v, anchorView); + final View thumbnailView = v.findViewById(R.id.app_thumbnail); + mCallback.handleLongPress(v, anchorView, thumbnailView); return true; } }; -- cgit v1.1