1 /* 2 * Copyright (C) 2018 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.quickstep.views; 18 19 import static com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch.TAP; 20 import static com.android.launcher3.userevent.nano.LauncherLogProto.ControlType.CLEAR_ALL_BUTTON; 21 22 import android.content.Context; 23 import android.graphics.Rect; 24 import android.util.AttributeSet; 25 import android.util.FloatProperty; 26 import android.view.MotionEvent; 27 import android.view.View; 28 29 import com.android.launcher3.InsettableFrameLayout; 30 import com.android.launcher3.R; 31 32 import java.util.ArrayList; 33 34 public class RecentsViewContainer extends InsettableFrameLayout { 35 public static final FloatProperty<RecentsViewContainer> CONTENT_ALPHA = 36 new FloatProperty<RecentsViewContainer>("contentAlpha") { 37 @Override 38 public void setValue(RecentsViewContainer view, float v) { 39 view.setContentAlpha(v); 40 } 41 42 @Override 43 public Float get(RecentsViewContainer view) { 44 return view.mRecentsView.getContentAlpha(); 45 } 46 }; 47 48 private final Rect mTempRect = new Rect(); 49 50 private RecentsView mRecentsView; 51 private ClearAllButton mClearAllButton; 52 53 public RecentsViewContainer(Context context, AttributeSet attrs) { 54 super(context, attrs); 55 } 56 57 @Override 58 protected void onFinishInflate() { 59 super.onFinishInflate(); 60 61 mClearAllButton = findViewById(R.id.clear_all_button); 62 mClearAllButton.setOnClickListener((v) -> { 63 mRecentsView.mActivity.getUserEventDispatcher() 64 .logActionOnControl(TAP, CLEAR_ALL_BUTTON); 65 mRecentsView.dismissAllTasks(); 66 }); 67 68 mRecentsView = findViewById(R.id.overview_panel); 69 mClearAllButton.forceHasOverlappingRendering(false); 70 71 mRecentsView.setClearAllButton(mClearAllButton); 72 mClearAllButton.setRecentsView(mRecentsView); 73 74 if (mRecentsView.isRtl()) { 75 mClearAllButton.setNextFocusRightId(mRecentsView.getId()); 76 mRecentsView.setNextFocusLeftId(mClearAllButton.getId()); 77 } else { 78 mClearAllButton.setNextFocusLeftId(mRecentsView.getId()); 79 mRecentsView.setNextFocusRightId(mClearAllButton.getId()); 80 } 81 } 82 83 @Override 84 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 85 super.onLayout(changed, left, top, right, bottom); 86 87 mRecentsView.getTaskSize(mTempRect); 88 89 mClearAllButton.setTranslationX( 90 (mRecentsView.isRtl() ? 1 : -1) * 91 (getResources().getDimension(R.dimen.clear_all_container_width) 92 - mClearAllButton.getMeasuredWidth()) / 2); 93 mClearAllButton.setTranslationY( 94 mTempRect.top + (mTempRect.height() - mClearAllButton.getMeasuredHeight()) / 2 95 - mClearAllButton.getTop()); 96 } 97 98 @Override 99 public boolean onTouchEvent(MotionEvent ev) { 100 super.onTouchEvent(ev); 101 // Do not let touch escape to siblings below this view. This prevents scrolling of the 102 // workspace while in Recents. 103 return true; 104 } 105 106 public void setContentAlpha(float alpha) { 107 if (alpha == mRecentsView.getContentAlpha()) { 108 return; 109 } 110 mRecentsView.setContentAlpha(alpha); 111 setVisibility(alpha > 0 ? VISIBLE : GONE); 112 } 113 114 @Override 115 public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { 116 if (mRecentsView.getChildCount() > 0) { 117 // Carousel is first in tab order. 118 views.add(mRecentsView); 119 views.add(mClearAllButton); 120 } 121 } 122 123 public boolean requestFocus(int direction, Rect previouslyFocusedRect) { 124 return mRecentsView.requestFocus(direction, previouslyFocusedRect) || 125 super.requestFocus(direction, previouslyFocusedRect); 126 } 127 128 @Override 129 public void addChildrenForAccessibility(ArrayList<View> outChildren) { 130 outChildren.add(mRecentsView); 131 } 132 }