Part 2: Adding clear-all to history
Change-Id: I9cd51f2a97ebe0f306e4934cdcac1a522526cf50
diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
index 41739c4..b59ff30 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java
@@ -34,7 +34,6 @@
import android.view.View;
import android.view.ViewOutlineProvider;
import android.view.ViewPropertyAnimator;
-import android.view.ViewStub;
import android.view.WindowInsets;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
@@ -51,6 +50,7 @@
import com.android.systemui.recents.RecentsConfiguration;
import com.android.systemui.recents.RecentsDebugFlags;
import com.android.systemui.recents.events.EventBus;
+import com.android.systemui.recents.events.activity.ClearHistoryEvent;
import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent;
import com.android.systemui.recents.events.activity.HideHistoryButtonEvent;
@@ -99,6 +99,7 @@
private TaskStackView mTaskStackView;
private RecentsAppWidgetHostView mSearchBar;
private TextView mHistoryButton;
+ private TextView mHistoryClearAllButton;
private View mEmptyView;
private RecentsHistoryView mHistoryView;
@@ -154,6 +155,7 @@
EventBus.getDefault().send(new ToggleHistoryEvent());
}
});
+ addView(mHistoryButton);
mHistoryButton.setClipToOutline(true);
mHistoryButton.setOutlineProvider(new ViewOutlineProvider() {
@Override
@@ -161,7 +163,6 @@
outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius);
}
});
- addView(mHistoryButton);
mEmptyView = inflater.inflate(R.layout.recents_empty, this, false);
addView(mEmptyView);
@@ -406,6 +407,11 @@
measureChild(mHistoryButton,
MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST));
+ if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) {
+ measureChild(mHistoryClearAllButton,
+ MeasureSpec.makeMeasureSpec(historyButtonRect.width(), MeasureSpec.AT_MOST),
+ MeasureSpec.makeMeasureSpec(historyButtonRect.height(), MeasureSpec.AT_MOST));
+ }
setMeasuredDimension(width, height);
}
@@ -441,16 +447,33 @@
mHistoryView.layout(left, top, right, bottom);
}
- // Layout the history button such that its drawable is left-aligned with the stack,
+ // Layout the history button such that its drawable is start-aligned with the stack,
// vertically centered in the available space above the stack
Rect historyButtonRect = mTaskStackView.mLayoutAlgorithm.mHistoryButtonRect;
- int historyLeft = historyButtonRect.left - mHistoryButton.getPaddingStart();
+ int historyLeft = isLayoutRtl()
+ ? historyButtonRect.right + mHistoryButton.getPaddingStart()
+ - mHistoryButton.getMeasuredWidth()
+ : historyButtonRect.left - mHistoryButton.getPaddingStart();
int historyTop = historyButtonRect.top +
(historyButtonRect.height() - mHistoryButton.getMeasuredHeight()) / 2;
mHistoryButton.layout(historyLeft, historyTop,
historyLeft + mHistoryButton.getMeasuredWidth(),
historyTop + mHistoryButton.getMeasuredHeight());
+ // Layout the history clear all button such that it is end-aligned with the stack,
+ // vertically centered in the available space above the stack
+ if (mHistoryClearAllButton != null && mHistoryClearAllButton.getVisibility() != GONE) {
+ int clearAllLeft = isLayoutRtl()
+ ? historyButtonRect.left - mHistoryClearAllButton.getPaddingStart()
+ : historyButtonRect.right + mHistoryClearAllButton.getPaddingStart()
+ - mHistoryClearAllButton.getMeasuredWidth();
+ int clearAllTop = historyButtonRect.top +
+ (historyButtonRect.height() - mHistoryClearAllButton.getMeasuredHeight()) / 2;
+ mHistoryClearAllButton.layout(clearAllLeft, clearAllTop,
+ clearAllLeft + mHistoryClearAllButton.getMeasuredWidth(),
+ clearAllTop + mHistoryClearAllButton.getMeasuredHeight());
+ }
+
if (mAwaitingFirstLayout) {
mAwaitingFirstLayout = false;
@@ -665,16 +688,37 @@
public final void onBusEvent(ShowHistoryEvent event) {
if (mHistoryView == null) {
- mHistoryView = (RecentsHistoryView) LayoutInflater.from(getContext()).inflate(
- R.layout.recents_history, this, false);
+ LayoutInflater inflater = LayoutInflater.from(getContext());
+ mHistoryView = (RecentsHistoryView) inflater.inflate(R.layout.recents_history, this,
+ false);
addView(mHistoryView);
+ final float cornerRadius = getResources().getDimensionPixelSize(
+ R.dimen.recents_task_view_rounded_corners_radius);
+ mHistoryClearAllButton = (TextView) inflater.inflate(
+ R.layout.recents_history_clear_all_button, this, false);
+ mHistoryClearAllButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ EventBus.getDefault().send(new ClearHistoryEvent());
+ }
+ });
+ mHistoryClearAllButton.setClipToOutline(true);
+ mHistoryClearAllButton.setOutlineProvider(new ViewOutlineProvider() {
+ @Override
+ public void getOutline(View view, Outline outline) {
+ outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), cornerRadius);
+ }
+ });
+ addView(mHistoryClearAllButton);
+
// Since this history view is inflated by a view stub after the insets have already
// been applied, we have to set them ourselves initial from the insets that were last
// provided.
mHistoryView.setSystemInsets(mSystemInsets);
mHistoryView.setHeaderHeight(mHistoryButton.getMeasuredHeight());
mHistoryButton.bringToFront();
+ mHistoryClearAllButton.bringToFront();
}
// Animate the empty view in parallel with the history view (the task view animations are
@@ -685,7 +729,7 @@
R.integer.recents_history_transition_duration);
mEmptyView.animate()
.alpha(0f)
- .translationY(stackRect.bottom)
+ .translationY(stackRect.height() / 2)
.setDuration(historyTransitionDuration)
.setInterpolator(mFastOutSlowInInterpolator)
.withEndAction(new Runnable() {
@@ -697,7 +741,7 @@
.start();
}
- mHistoryView.show(mStack, stackRect.height());
+ mHistoryView.show(mStack, stackRect.height(), mHistoryClearAllButton);
}
public final void onBusEvent(HideHistoryEvent event) {
@@ -716,7 +760,7 @@
.start();
}
- mHistoryView.hide(event.animate, stackRect.height());
+ mHistoryView.hide(event.animate, stackRect.height(), mHistoryClearAllButton);
}
public final void onBusEvent(ShowHistoryButtonEvent event) {
@@ -737,6 +781,8 @@
mHistoryButton.setAlpha(0f);
if (translate) {
mHistoryButton.setTranslationY(-mHistoryButton.getMeasuredHeight() * 0.25f);
+ } else {
+ mHistoryButton.setTranslationY(0f);
}
postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
@Override