[Predictive Back] Refactor setClipChildrenOnViewTree/restoreClipChildrenOnViewTree to support clipToPadding
Bug: 325930715 Test: Added unit test Flag: aconfig com.android.launcher3.enable_predictive_back_gesture TEAMFOOD Change-Id: I509546ac4ee1fa851cf0648d365a5348362267cc
This commit is contained in:
1 parent
c51363fc46
commit
ea7cb497f5
5 files changed
+296
-146
No files matched your search
@@ -68,8 +68,6 @@ import android.util.TypedValue;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import androidx.annotation.ChecksSdkIntAtLeast;
|
||||
@@ -774,136 +772,6 @@ public final class Utilities {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively call {@link ViewGroup#setClipChildren(boolean)} from {@link View} to ts parent
|
||||
* (direct or indirect) inclusive. This method will also save the old clipChildren value on each
|
||||
* view with {@link View#setTag(int, Object)}, which can be restored in
|
||||
* {@link #restoreClipChildrenOnViewTree(View, ViewParent)}.
|
||||
*
|
||||
* Note that if parent is null or not a parent of the view, this method will be applied all the
|
||||
* way to root view.
|
||||
*
|
||||
* @param v child view
|
||||
* @param parent direct or indirect parent of child view
|
||||
* @param clipChildren whether we should clip children
|
||||
*/
|
||||
public static void setClipChildrenOnViewTree(
|
||||
@Nullable View v,
|
||||
@Nullable ViewParent parent,
|
||||
boolean clipChildren) {
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v instanceof ViewGroup) {
|
||||
ViewGroup viewGroup = (ViewGroup) v;
|
||||
boolean oldClipChildren = viewGroup.getClipChildren();
|
||||
if (oldClipChildren != clipChildren) {
|
||||
v.setTag(R.id.saved_clip_children_tag_id, oldClipChildren);
|
||||
viewGroup.setClipChildren(clipChildren);
|
||||
}
|
||||
}
|
||||
|
||||
if (v == parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v.getParent() instanceof View) {
|
||||
setClipChildrenOnViewTree((View) v.getParent(), parent, clipChildren);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively call {@link ViewGroup#setClipChildren(boolean)} to restore clip children value
|
||||
* set in {@link #setClipChildrenOnViewTree(View, ViewParent, boolean)} on view to its parent
|
||||
* (direct or indirect) inclusive.
|
||||
*
|
||||
* Note that if parent is null or not a parent of the view, this method will be applied all the
|
||||
* way to root view.
|
||||
*
|
||||
* @param v child view
|
||||
* @param parent direct or indirect parent of child view
|
||||
*/
|
||||
public static void restoreClipChildrenOnViewTree(
|
||||
@Nullable View v, @Nullable ViewParent parent) {
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
if (v instanceof ViewGroup) {
|
||||
ViewGroup viewGroup = (ViewGroup) v;
|
||||
Object viewTag = viewGroup.getTag(R.id.saved_clip_children_tag_id);
|
||||
if (viewTag instanceof Boolean) {
|
||||
viewGroup.setClipChildren((boolean) viewTag);
|
||||
viewGroup.setTag(R.id.saved_clip_children_tag_id, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (v == parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v.getParent() instanceof View) {
|
||||
restoreClipChildrenOnViewTree((View) v.getParent(), parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #setClipChildrenOnViewTree(View, ViewParent, boolean)} but is calling
|
||||
* {@link ViewGroup#setClipToPadding}.
|
||||
*/
|
||||
public static void setClipToPaddingOnViewTree(
|
||||
@Nullable View v,
|
||||
@Nullable ViewParent parent,
|
||||
boolean clipToPadding) {
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v instanceof ViewGroup) {
|
||||
ViewGroup viewGroup = (ViewGroup) v;
|
||||
boolean oldClipToPadding = viewGroup.getClipToPadding();
|
||||
if (oldClipToPadding != clipToPadding) {
|
||||
v.setTag(R.id.saved_clip_to_padding_tag_id, oldClipToPadding);
|
||||
viewGroup.setClipToPadding(clipToPadding);
|
||||
}
|
||||
}
|
||||
|
||||
if (v == parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v.getParent() instanceof View) {
|
||||
setClipToPaddingOnViewTree((View) v.getParent(), parent, clipToPadding);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #restoreClipChildrenOnViewTree(View, ViewParent)} but is calling
|
||||
* {@link ViewGroup#setClipToPadding}.
|
||||
*/
|
||||
public static void restoreClipToPaddingOnViewTree(
|
||||
@Nullable View v, @Nullable ViewParent parent) {
|
||||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
if (v instanceof ViewGroup) {
|
||||
ViewGroup viewGroup = (ViewGroup) v;
|
||||
Object viewTag = viewGroup.getTag(R.id.saved_clip_to_padding_tag_id);
|
||||
if (viewTag instanceof Boolean) {
|
||||
viewGroup.setClipToPadding((boolean) viewTag);
|
||||
viewGroup.setTag(R.id.saved_clip_to_padding_tag_id, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (v == parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v.getParent() instanceof View) {
|
||||
restoreClipToPaddingOnViewTree((View) v.getParent(), parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the {@code targetView} so that it overlaps with {@code exclusionBounds} as little
|
||||
* as possible, while remaining within {@code inclusionBounds}.
|
||||
|
||||
Reference in new issue
Block a user