Files
Lawnchair/src/com/android/launcher3/anim/KeyboardInsetAnimationCallback.java
T
Andy Wickham 64896f3098 Put the "floating" in ENABLE_FLOATING_SEARCH_BAR.
This means adding the search view to the drag layer, so it can
persist and animate across Launcher states (i.e. Home, All Apps,
Overview, Overview from App).

Some high level things:
 - LauncherState now has a flag indicating if the floating
   search bar should be visible, as well as a method indicating
   how high it should rest when the keyboard is not showing. By
   default the height is set negative if the flag is not present,
   so the search bar will rest off screen in that state.
 - LauncherState also has a new method indicating if the search
   bar should show as a pill when not focused. Currently this is
   done in phone portrait mode in all apps and overview.
 - SearchUiManager now has a method for gestures to hint that
   the search bar will be focused or unfocused soon, e.g. for
   the app -> overview case, we hint that it will be focused
   when crossing the threshold, and unfocused if retracting.
   This allows the search bar to animate during the gesture
   and take or release focus after the state change completes.
 - AllAppsTransitionController lets the apps panel translate in
   from the bottom of the screen, for example when coming from
   an app and we don't want to pop it in halfway up the screen.
   Instead it can slide in gracefully from behind the keyboard
   and floating search bar.
 - KeyboardInsetAnimationCallback can now notify listeners of
   keyboard alpha changes during controlled animations. And
   StateAnimationConfig has a new animation type to control
   the keyboard alpha during the all apps transition.
 - This new ANIM_ALL_APPS_KEYBOARD_FADE is used to pop the
   keyboard in at the threshold for going from an app to all apps.
   Note that its position moves linearly before this, so the
   search bar starts moving up accordingly before the keyboard
   alpha is non-0.

Fix: 266761289
Fix: 268845147
Fix: 267683921
Fix: 265849321
Fix: 266446733
Fix: 269301440
Bug: 275635606
Bug: 259619990
Bug: 261866704
Test: Manual with all the state transitions on phone and tablet
(also folding/unfolding foldable).
Flag: ENABLE_FLOATING_SEARCH_BAR, ENABLE_ALL_APPS_FROM_OVERVIEW
(latter just for the background app interpolator changes).

Change-Id: I6f06552e95747348a62260279626cf407bf145b0
2023-06-12 21:55:24 +00:00

147 lines
5.2 KiB
Java

/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.anim;
import android.os.Build;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowInsetsAnimation;
import androidx.annotation.RequiresApi;
import com.android.launcher3.Utilities;
import java.util.List;
/**
* Callback that animates views above the IME.
* <p>
* The expected stages of a keyboard transition are:
* <p>
* <ul>
* <li>PREPARING: Keyboard insets haven't changed yet, but are about to.</li>
* <li>STARTED: Keyboard insets have temporarily changed to the end state, but not drawn.</li>
* <li>PROGRESSING: At least one frame of the animation has been drawn.</li>
* <li>FINISHED: Keyboard has reached its end state, and animation is complete.</li>
* </ul>
*/
@RequiresApi(api = Build.VERSION_CODES.R)
public class KeyboardInsetAnimationCallback extends WindowInsetsAnimation.Callback {
private final View mView;
private float mInitialTranslation;
private float mTerminalTranslation;
private KeyboardTranslationState mKeyboardTranslationState = KeyboardTranslationState.SYSTEM;
/** Current state of the keyboard. */
public enum KeyboardTranslationState {
// We are not controlling the keyboard, and it may or may not be translating.
SYSTEM,
// We are about to gain control of the keyboard, but the current state may be transient.
MANUAL_PREPARED,
// We are manually translating the keyboard.
MANUAL_ONGOING
}
public KeyboardInsetAnimationCallback(View view) {
super(DISPATCH_MODE_STOP);
mView = view;
}
public KeyboardTranslationState getKeyboardTranslationState() {
return mKeyboardTranslationState;
}
@Override
public void onPrepare(WindowInsetsAnimation animation) {
mKeyboardTranslationState = KeyboardTranslationState.MANUAL_PREPARED;
mInitialTranslation = mView.getTranslationY();
}
@Override
public WindowInsetsAnimation.Bounds onStart(WindowInsetsAnimation animation,
WindowInsetsAnimation.Bounds bounds) {
// Final insets have temporarily been applied, so store the current translation as final.
mTerminalTranslation = mView.getTranslationY();
// Reset the translation in case the view is drawn before onProgress gets called.
mView.setTranslationY(mInitialTranslation);
mKeyboardTranslationState = KeyboardTranslationState.MANUAL_ONGOING;
if (mView instanceof KeyboardInsetListener) {
((KeyboardInsetListener) mView).onTranslationStart();
}
return super.onStart(animation, bounds);
}
@Override
public WindowInsets onProgress(WindowInsets windowInsets, List<WindowInsetsAnimation> list) {
if (list.size() == 0) {
mView.setTranslationY(mInitialTranslation);
return windowInsets;
}
WindowInsetsAnimation animation = list.get(0);
if (animation.getDurationMillis() > -1) {
float progress = animation.getInterpolatedFraction();
mView.setTranslationY(
Utilities.mapRange(progress, mInitialTranslation, mTerminalTranslation));
} else {
// Manually controlled animation: Set translation to keyboard height.
int translationY = -windowInsets.getInsets(WindowInsets.Type.ime()).bottom;
if (mView.getParent() instanceof View) {
// Offset any translation of the parent (e.g. All Apps parallax).
translationY -= ((View) mView.getParent()).getTranslationY();
}
mView.setTranslationY(translationY);
}
if (mView instanceof KeyboardInsetListener) {
((KeyboardInsetListener) mView).onKeyboardAlphaChanged(animation.getAlpha());
}
return windowInsets;
}
@Override
public void onEnd(WindowInsetsAnimation animation) {
if (mView instanceof KeyboardInsetListener) {
((KeyboardInsetListener) mView).onTranslationEnd();
}
mKeyboardTranslationState = KeyboardTranslationState.SYSTEM;
}
/**
* Interface Allowing views to listen for keyboard translation events
*/
public interface KeyboardInsetListener {
/**
* Called from {@link KeyboardInsetAnimationCallback#onStart}
*/
void onTranslationStart();
/**
* Called from {@link KeyboardInsetAnimationCallback#onProgress}
*
* @param alpha the current IME alpha
*/
default void onKeyboardAlphaChanged(float alpha) {}
/**
* Called from {@link KeyboardInsetAnimationCallback#onEnd}
*/
void onTranslationEnd();
}
}