Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.recent; |
| 18 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 19 | import android.animation.LayoutTransition; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Jim Miller | 3c728fe | 2011-07-07 20:53:52 -0700 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 22 | import android.database.DataSetObserver; |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 23 | import android.graphics.Canvas; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 25 | import android.util.DisplayMetrics; |
| 26 | import android.util.FloatMath; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 27 | import android.util.Log; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 28 | import android.view.MotionEvent; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 29 | import android.view.View; |
Jim Miller | 3c728fe | 2011-07-07 20:53:52 -0700 | [diff] [blame] | 30 | import android.view.ViewConfiguration; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 31 | import android.view.ViewTreeObserver; |
| 32 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 33 | import android.widget.LinearLayout; |
| 34 | import android.widget.ScrollView; |
| 35 | |
| 36 | import com.android.systemui.R; |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 37 | import com.android.systemui.SwipeHelper; |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 38 | import com.android.systemui.recent.RecentsPanelView.TaskDescriptionAdapter; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 39 | |
Michael Jurka | d1a040c | 2012-06-06 10:05:46 -0700 | [diff] [blame] | 40 | import java.util.HashSet; |
| 41 | import java.util.Iterator; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 42 | |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 43 | public class RecentsVerticalScrollView extends ScrollView |
| 44 | implements SwipeHelper.Callback, RecentsPanelView.RecentsScrollView { |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 45 | private static final String TAG = RecentsPanelView.TAG; |
Jim Miller | 3c728fe | 2011-07-07 20:53:52 -0700 | [diff] [blame] | 46 | private static final boolean DEBUG = RecentsPanelView.DEBUG; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 47 | private LinearLayout mLinearLayout; |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 48 | private TaskDescriptionAdapter mAdapter; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 49 | private RecentsCallback mCallback; |
| 50 | protected int mLastScrollPosition; |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 51 | private SwipeHelper mSwipeHelper; |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 52 | private FadedEdgeDrawHelper mFadedEdgeDrawHelper; |
Michael Jurka | d1a040c | 2012-06-06 10:05:46 -0700 | [diff] [blame] | 53 | private HashSet<View> mRecycledViews; |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 54 | private int mNumItemsInOneScreenful; |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 55 | private Runnable mOnScrollListener; |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 56 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 57 | public RecentsVerticalScrollView(Context context, AttributeSet attrs) { |
| 58 | super(context, attrs, 0); |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 59 | float densityScale = getResources().getDisplayMetrics().density; |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 60 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 61 | mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop); |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 62 | |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 63 | mFadedEdgeDrawHelper = FadedEdgeDrawHelper.create(context, attrs, this, true); |
Michael Jurka | d1a040c | 2012-06-06 10:05:46 -0700 | [diff] [blame] | 64 | mRecycledViews = new HashSet<View>(); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Michael Jurka | 4eaa983 | 2012-02-29 15:51:49 -0800 | [diff] [blame] | 67 | public void setMinSwipeAlpha(float minAlpha) { |
| 68 | mSwipeHelper.setMinAlpha(minAlpha); |
| 69 | } |
| 70 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 71 | private int scrollPositionOfMostRecent() { |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 72 | return mLinearLayout.getHeight() - getHeight() + getPaddingTop(); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Michael Jurka | 261277e | 2012-06-01 04:06:45 -0700 | [diff] [blame] | 75 | private void addToRecycledViews(View v) { |
| 76 | if (mRecycledViews.size() < mNumItemsInOneScreenful) { |
| 77 | mRecycledViews.add(v); |
| 78 | } |
| 79 | } |
| 80 | |
Michael Jurka | e592363 | 2012-10-03 15:29:36 +0200 | [diff] [blame] | 81 | public View findViewForTask(int persistentTaskId) { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 82 | for (int i = 0; i < mLinearLayout.getChildCount(); i++) { |
| 83 | View v = mLinearLayout.getChildAt(i); |
| 84 | RecentsPanelView.ViewHolder holder = (RecentsPanelView.ViewHolder) v.getTag(); |
Michael Jurka | e592363 | 2012-10-03 15:29:36 +0200 | [diff] [blame] | 85 | if (holder.taskDescription.persistentTaskId == persistentTaskId) { |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 86 | return v; |
| 87 | } |
| 88 | } |
| 89 | return null; |
| 90 | } |
| 91 | |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 92 | private void update() { |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 93 | for (int i = 0; i < mLinearLayout.getChildCount(); i++) { |
| 94 | View v = mLinearLayout.getChildAt(i); |
Michael Jurka | 261277e | 2012-06-01 04:06:45 -0700 | [diff] [blame] | 95 | addToRecycledViews(v); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 96 | mAdapter.recycleView(v); |
| 97 | } |
| 98 | LayoutTransition transitioner = getLayoutTransition(); |
| 99 | setLayoutTransition(null); |
| 100 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 101 | mLinearLayout.removeAllViews(); |
Michael Jurka | d1a040c | 2012-06-06 10:05:46 -0700 | [diff] [blame] | 102 | |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 103 | // Once we can clear the data associated with individual item views, |
| 104 | // we can get rid of the removeAllViews() and the code below will |
| 105 | // recycle them. |
Michael Jurka | d1a040c | 2012-06-06 10:05:46 -0700 | [diff] [blame] | 106 | Iterator<View> recycledViews = mRecycledViews.iterator(); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 107 | for (int i = 0; i < mAdapter.getCount(); i++) { |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 108 | View old = null; |
Michael Jurka | d1a040c | 2012-06-06 10:05:46 -0700 | [diff] [blame] | 109 | if (recycledViews.hasNext()) { |
| 110 | old = recycledViews.next(); |
| 111 | recycledViews.remove(); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 112 | old.setVisibility(VISIBLE); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 113 | } |
| 114 | final View view = mAdapter.getView(i, old, mLinearLayout); |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 115 | |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 116 | if (mFadedEdgeDrawHelper != null) { |
| 117 | mFadedEdgeDrawHelper.addViewCallback(view); |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 120 | OnTouchListener noOpListener = new OnTouchListener() { |
| 121 | @Override |
| 122 | public boolean onTouch(View v, MotionEvent event) { |
| 123 | return true; |
| 124 | } |
| 125 | }; |
Michael Jurka | 7daf95d | 2011-09-30 11:07:30 -0700 | [diff] [blame] | 126 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 127 | view.setOnClickListener(new OnClickListener() { |
| 128 | public void onClick(View v) { |
| 129 | mCallback.dismiss(); |
| 130 | } |
| 131 | }); |
| 132 | // We don't want a click sound when we dimiss recents |
| 133 | view.setSoundEffectsEnabled(false); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 134 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 135 | OnClickListener launchAppListener = new OnClickListener() { |
| 136 | public void onClick(View v) { |
| 137 | mCallback.handleOnClick(view); |
| 138 | } |
| 139 | }; |
Michael Jurka | 7daf95d | 2011-09-30 11:07:30 -0700 | [diff] [blame] | 140 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 141 | RecentsPanelView.ViewHolder holder = (RecentsPanelView.ViewHolder) view.getTag(); |
| 142 | final View thumbnailView = holder.thumbnailView; |
| 143 | OnLongClickListener longClickListener = new OnLongClickListener() { |
| 144 | public boolean onLongClick(View v) { |
| 145 | final View anchorView = view.findViewById(R.id.app_description); |
| 146 | mCallback.handleLongPress(view, anchorView, thumbnailView); |
| 147 | return true; |
| 148 | } |
| 149 | }; |
| 150 | thumbnailView.setClickable(true); |
| 151 | thumbnailView.setOnClickListener(launchAppListener); |
| 152 | thumbnailView.setOnLongClickListener(longClickListener); |
Michael Jurka | 7daf95d | 2011-09-30 11:07:30 -0700 | [diff] [blame] | 153 | |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 154 | // We don't want to dismiss recents if a user clicks on the app title |
| 155 | // (we also don't want to launch the app either, though, because the |
| 156 | // app title is a small target and doesn't have great click feedback) |
| 157 | final View appTitle = view.findViewById(R.id.app_label); |
| 158 | appTitle.setContentDescription(" "); |
| 159 | appTitle.setOnTouchListener(noOpListener); |
| 160 | final View calloutLine = view.findViewById(R.id.recents_callout_line); |
Michael Jurka | cb2522c | 2012-04-13 09:32:47 -0700 | [diff] [blame] | 161 | if (calloutLine != null) { |
| 162 | calloutLine.setOnTouchListener(noOpListener); |
| 163 | } |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 164 | |
| 165 | mLinearLayout.addView(view); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 166 | } |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 167 | setLayoutTransition(transitioner); |
| 168 | |
Michael Jurka | 9a0890c | 2012-10-02 14:42:53 +0200 | [diff] [blame] | 169 | // Scroll to end after initial layout. |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 170 | final OnGlobalLayoutListener updateScroll = new OnGlobalLayoutListener() { |
| 171 | public void onGlobalLayout() { |
| 172 | mLastScrollPosition = scrollPositionOfMostRecent(); |
| 173 | scrollTo(0, mLastScrollPosition); |
Michael Jurka | 9a0890c | 2012-10-02 14:42:53 +0200 | [diff] [blame] | 174 | final ViewTreeObserver observer = getViewTreeObserver(); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 175 | if (observer.isAlive()) { |
| 176 | observer.removeOnGlobalLayoutListener(this); |
| 177 | } |
| 178 | } |
| 179 | }; |
Michael Jurka | 9a0890c | 2012-10-02 14:42:53 +0200 | [diff] [blame] | 180 | getViewTreeObserver().addOnGlobalLayoutListener(updateScroll); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | @Override |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 184 | public void removeViewInLayout(final View view) { |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 185 | dismissChild(view); |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 188 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 189 | if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()"); |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 190 | return mSwipeHelper.onInterceptTouchEvent(ev) || |
| 191 | super.onInterceptTouchEvent(ev); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public boolean onTouchEvent(MotionEvent ev) { |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 196 | return mSwipeHelper.onTouchEvent(ev) || |
| 197 | super.onTouchEvent(ev); |
| 198 | } |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 199 | |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 200 | public boolean canChildBeDismissed(View v) { |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 201 | return true; |
| 202 | } |
| 203 | |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 204 | public void dismissChild(View v) { |
| 205 | mSwipeHelper.dismissChild(v, 0); |
Jim Miller | c0d2731 | 2011-07-14 18:54:01 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 208 | public void onChildDismissed(View v) { |
Michael Jurka | 261277e | 2012-06-01 04:06:45 -0700 | [diff] [blame] | 209 | addToRecycledViews(v); |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 210 | mLinearLayout.removeView(v); |
| 211 | mCallback.handleSwipe(v); |
Michael Jurka | 2db72fc | 2012-02-23 17:16:11 -0800 | [diff] [blame] | 212 | // Restore the alpha/translation parameters to what they were before swiping |
| 213 | // (for when these items are recycled) |
| 214 | View contentView = getChildContentView(v); |
| 215 | contentView.setAlpha(1f); |
| 216 | contentView.setTranslationX(0); |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | public void onBeginDrag(View v) { |
Michael Jurka | 13451a4 | 2011-08-22 15:54:21 -0700 | [diff] [blame] | 220 | // We do this so the underlying ScrollView knows that it won't get |
| 221 | // the chance to intercept events anymore |
| 222 | requestDisallowInterceptTouchEvent(true); |
Peter Ng | 622a976 | 2011-08-29 10:56:53 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | public void onDragCancelled(View v) { |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | public View getChildAtPosition(MotionEvent ev) { |
| 229 | final float x = ev.getX() + getScrollX(); |
| 230 | final float y = ev.getY() + getScrollY(); |
| 231 | for (int i = 0; i < mLinearLayout.getChildCount(); i++) { |
| 232 | View item = mLinearLayout.getChildAt(i); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 233 | if (item.getVisibility() == View.VISIBLE |
| 234 | && x >= item.getLeft() && x < item.getRight() |
| 235 | && y >= item.getTop() && y < item.getBottom()) { |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 236 | return item; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 239 | return null; |
| 240 | } |
| 241 | |
| 242 | public View getChildContentView(View v) { |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 243 | return v.findViewById(R.id.recent_item); |
| 244 | } |
| 245 | |
| 246 | @Override |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 247 | public void drawFadedEdges(Canvas canvas, int left, int right, int top, int bottom) { |
| 248 | if (mFadedEdgeDrawHelper != null) { |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 249 | final boolean offsetRequired = isPaddingOffsetRequired(); |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 250 | mFadedEdgeDrawHelper.drawCallback(canvas, |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 251 | left, right, top + getFadeTop(offsetRequired), bottom, getScrollX(), getScrollY(), |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 252 | getTopFadingEdgeStrength(), getBottomFadingEdgeStrength(), |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 253 | 0, 0, getPaddingTop()); |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | @Override |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 258 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
| 259 | super.onScrollChanged(l, t, oldl, oldt); |
| 260 | if (mOnScrollListener != null) { |
| 261 | mOnScrollListener.run(); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | public void setOnScrollListener(Runnable listener) { |
| 266 | mOnScrollListener = listener; |
| 267 | } |
| 268 | |
| 269 | @Override |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 270 | public int getVerticalFadingEdgeLength() { |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 271 | if (mFadedEdgeDrawHelper != null) { |
| 272 | return mFadedEdgeDrawHelper.getVerticalFadingEdgeLength(); |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 273 | } else { |
| 274 | return super.getVerticalFadingEdgeLength(); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | public int getHorizontalFadingEdgeLength() { |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 280 | if (mFadedEdgeDrawHelper != null) { |
| 281 | return mFadedEdgeDrawHelper.getHorizontalFadingEdgeLength(); |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 282 | } else { |
| 283 | return super.getHorizontalFadingEdgeLength(); |
| 284 | } |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | @Override |
| 288 | protected void onFinishInflate() { |
| 289 | super.onFinishInflate(); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 290 | setScrollbarFadingEnabled(true); |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 291 | mLinearLayout = (LinearLayout) findViewById(R.id.recents_linear_layout); |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 292 | final int leftPadding = getContext().getResources() |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 293 | .getDimensionPixelOffset(R.dimen.status_bar_recents_thumbnail_left_margin); |
| 294 | setOverScrollEffectPadding(leftPadding, 0); |
| 295 | } |
| 296 | |
Jim Miller | 3c728fe | 2011-07-07 20:53:52 -0700 | [diff] [blame] | 297 | @Override |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 298 | public void onAttachedToWindow() { |
Michael Jurka | 4a6bc55 | 2013-09-17 17:42:54 +0200 | [diff] [blame] | 299 | if (mFadedEdgeDrawHelper != null) { |
| 300 | mFadedEdgeDrawHelper.onAttachedToWindowCallback(mLinearLayout, isHardwareAccelerated()); |
Michael Jurka | 3cd0a59 | 2011-08-16 12:40:30 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | @Override |
Jim Miller | 3c728fe | 2011-07-07 20:53:52 -0700 | [diff] [blame] | 305 | protected void onConfigurationChanged(Configuration newConfig) { |
| 306 | super.onConfigurationChanged(newConfig); |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 307 | float densityScale = getResources().getDisplayMetrics().density; |
| 308 | mSwipeHelper.setDensityScale(densityScale); |
John Spurlock | 0153478 | 2014-01-13 11:59:22 -0500 | [diff] [blame] | 309 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
Michael Jurka | 07d4046 | 2011-07-19 10:54:38 -0700 | [diff] [blame] | 310 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
Jim Miller | 3c728fe | 2011-07-07 20:53:52 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 313 | private void setOverScrollEffectPadding(int leftPadding, int i) { |
| 314 | // TODO Add to (Vertical)ScrollView |
| 315 | } |
| 316 | |
| 317 | @Override |
| 318 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 319 | super.onSizeChanged(w, h, oldw, oldh); |
Chet Haase | 81abe87 | 2011-08-10 13:53:43 -0700 | [diff] [blame] | 320 | |
| 321 | // Skip this work if a transition is running; it sets the scroll values independently |
| 322 | // and should not have those animated values clobbered by this logic |
| 323 | LayoutTransition transition = mLinearLayout.getLayoutTransition(); |
| 324 | if (transition != null && transition.isRunning()) { |
| 325 | return; |
| 326 | } |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 327 | // Keep track of the last visible item in the list so we can restore it |
| 328 | // to the bottom when the orientation changes. |
| 329 | mLastScrollPosition = scrollPositionOfMostRecent(); |
| 330 | |
| 331 | // This has to happen post-layout, so run it "in the future" |
| 332 | post(new Runnable() { |
| 333 | public void run() { |
Chet Haase | 81abe87 | 2011-08-10 13:53:43 -0700 | [diff] [blame] | 334 | // Make sure we're still not clobbering the transition-set values, since this |
| 335 | // runnable launches asynchronously |
| 336 | LayoutTransition transition = mLinearLayout.getLayoutTransition(); |
| 337 | if (transition == null || !transition.isRunning()) { |
| 338 | scrollTo(0, mLastScrollPosition); |
| 339 | } |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 340 | } |
| 341 | }); |
| 342 | } |
| 343 | |
Michael Jurka | ab48b68 | 2011-09-12 15:39:45 -0700 | [diff] [blame] | 344 | public void setAdapter(TaskDescriptionAdapter adapter) { |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 345 | mAdapter = adapter; |
| 346 | mAdapter.registerDataSetObserver(new DataSetObserver() { |
| 347 | public void onChanged() { |
| 348 | update(); |
| 349 | } |
| 350 | |
| 351 | public void onInvalidated() { |
| 352 | update(); |
| 353 | } |
| 354 | }); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 355 | |
| 356 | DisplayMetrics dm = getResources().getDisplayMetrics(); |
| 357 | int childWidthMeasureSpec = |
| 358 | MeasureSpec.makeMeasureSpec(dm.widthPixels, MeasureSpec.AT_MOST); |
| 359 | int childheightMeasureSpec = |
| 360 | MeasureSpec.makeMeasureSpec(dm.heightPixels, MeasureSpec.AT_MOST); |
| 361 | View child = mAdapter.createView(mLinearLayout); |
| 362 | child.measure(childWidthMeasureSpec, childheightMeasureSpec); |
| 363 | mNumItemsInOneScreenful = |
| 364 | (int) FloatMath.ceil(dm.heightPixels / (float) child.getMeasuredHeight()); |
Michael Jurka | 261277e | 2012-06-01 04:06:45 -0700 | [diff] [blame] | 365 | addToRecycledViews(child); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 366 | |
| 367 | for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) { |
Michael Jurka | 261277e | 2012-06-01 04:06:45 -0700 | [diff] [blame] | 368 | addToRecycledViews(mAdapter.createView(mLinearLayout)); |
Michael Jurka | 99a9655 | 2012-01-27 17:23:38 -0800 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
| 372 | public int numItemsInOneScreenful() { |
| 373 | return mNumItemsInOneScreenful; |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public void setLayoutTransition(LayoutTransition transition) { |
| 378 | // The layout transition applies to our embedded LinearLayout |
| 379 | mLinearLayout.setLayoutTransition(transition); |
| 380 | } |
| 381 | |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 382 | public void setCallback(RecentsCallback callback) { |
| 383 | mCallback = callback; |
| 384 | } |
Jim Miller | 9f0f0e0 | 2011-05-17 20:06:29 -0700 | [diff] [blame] | 385 | } |