Add OnComputeInsetsListener to TaskbarContainerView

Instead of updating visibility of TaskbarContainerView, keep it
VISIBLE but with alpha 0, and update touchableInsets to allow
touches to pass through. This avoids sending insets changed
when Taskbar is hidden.

Test: Swipe to Overview, no jumping/jank due to insets change;
also tap where Taskbar would be and ensure it doesn't launch

Bug: 171917176
Change-Id: I9ccb4335e0301f34eec459657f3bbaf88b0d8a52
This commit is contained in:
Tony Wickham
2021-02-02 11:04:25 -08:00
parent 63fc59b801
commit 734be0b5ae
2 changed files with 50 additions and 2 deletions

View File

@@ -15,6 +15,9 @@
*/
package com.android.launcher3.taskbar;
import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_FRAME;
import static com.android.systemui.shared.system.ViewTreeObserverWrapper.InsetsInfo.TOUCHABLE_INSETS_REGION;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
@@ -22,10 +25,18 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.anim.AlphaUpdateListener;
import com.android.systemui.shared.system.ViewTreeObserverWrapper;
/**
* Top-level ViewGroup that hosts the TaskbarView as well as Views created by it such as Folder.
*/
public class TaskbarContainerView extends FrameLayout {
// Initialized in init.
private TaskbarView mTaskbarView;
private ViewTreeObserverWrapper.OnComputeInsetsListener mTaskbarInsetsComputer;
public TaskbarContainerView(@NonNull Context context) {
this(context, null);
}
@@ -43,4 +54,41 @@ public class TaskbarContainerView extends FrameLayout {
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
protected void init(TaskbarView taskbarView) {
mTaskbarView = taskbarView;
mTaskbarInsetsComputer = createTaskbarInsetsComputer();
}
private ViewTreeObserverWrapper.OnComputeInsetsListener createTaskbarInsetsComputer() {
return insetsInfo -> {
if (getAlpha() < AlphaUpdateListener.ALPHA_CUTOFF_THRESHOLD) {
// We're invisible, let touches pass through us.
insetsInfo.touchableRegion.setEmpty();
insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION);
} else {
// We're visible again, accept touches anywhere in our bounds.
insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_FRAME);
}
};
}
protected void cleanup() {
ViewTreeObserverWrapper.removeOnComputeInsetsListener(mTaskbarInsetsComputer);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
ViewTreeObserverWrapper.addOnComputeInsetsListener(getViewTreeObserver(),
mTaskbarInsetsComputer);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
cleanup();
}
}