Merge "Refactor FolderInsetAnimationCallback to be used with any view" into sc-dev

This commit is contained in:
Samuel Fufa
2021-06-17 18:48:49 +00:00
committed by Android (Google) Code Review
12 changed files with 170 additions and 106 deletions

View File

@@ -19,6 +19,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import android.content.Context;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Build;
import android.os.Process;
@@ -27,13 +28,16 @@ import android.os.UserManager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.Button;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.android.launcher3.Insettable;
import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.KeyboardInsetAnimationCallback;
import com.android.launcher3.pm.UserCache;
/**
@@ -44,6 +48,10 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
private Rect mInsets = new Rect();
private boolean mWorkEnabled;
@Nullable
private KeyboardInsetAnimationCallback mKeyboardInsetAnimationCallback;
public WorkModeSwitch(Context context) {
this(context, null, 0);
}
@@ -60,6 +68,10 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
protected void onFinishInflate() {
super.onFinishInflate();
setOnClickListener(this);
if (Utilities.ATLEAST_R) {
mKeyboardInsetAnimationCallback = new KeyboardInsetAnimationCallback(this);
setWindowInsetsAnimationCallback(mKeyboardInsetAnimationCallback);
}
}
@Override
@@ -121,4 +133,16 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi
}
return showConfirm;
}
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (Utilities.ATLEAST_R) {
setTranslationY(0);
if (insets.isVisible(WindowInsets.Type.ime())) {
Insets keyboardInsets = insets.getInsets(WindowInsets.Type.ime());
setTranslationY(mInsets.bottom - keyboardInsets.bottom);
}
}
return insets;
}
}