Merge branch 'heads/android-14.0.0_r18' into 14-dev
This commit is contained in:
@@ -32,10 +32,12 @@ import java.util.List;
|
||||
* 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>
|
||||
* <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)
|
||||
@@ -44,24 +46,44 @@ public class KeyboardInsetAnimationCallback extends WindowInsetsAnimation.Callba
|
||||
|
||||
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.
|
||||
// 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.
|
||||
// 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();
|
||||
}
|
||||
@@ -90,6 +112,10 @@ public class KeyboardInsetAnimationCallback extends WindowInsetsAnimation.Callba
|
||||
mView.setTranslationY(translationY);
|
||||
}
|
||||
|
||||
if (mView instanceof KeyboardInsetListener) {
|
||||
((KeyboardInsetListener) mView).onKeyboardAlphaChanged(animation.getAlpha());
|
||||
}
|
||||
|
||||
return windowInsets;
|
||||
}
|
||||
|
||||
@@ -98,7 +124,7 @@ public class KeyboardInsetAnimationCallback extends WindowInsetsAnimation.Callba
|
||||
if (mView instanceof KeyboardInsetListener) {
|
||||
((KeyboardInsetListener) mView).onTranslationEnd();
|
||||
}
|
||||
super.onEnd(animation);
|
||||
mKeyboardTranslationState = KeyboardTranslationState.SYSTEM;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,6 +136,14 @@ public class KeyboardInsetAnimationCallback extends WindowInsetsAnimation.Callba
|
||||
*/
|
||||
void onTranslationStart();
|
||||
|
||||
/**
|
||||
* Called from {@link KeyboardInsetAnimationCallback#onProgress}
|
||||
*
|
||||
* @param alpha the current IME alpha
|
||||
*/
|
||||
default void onKeyboardAlphaChanged(float alpha) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from {@link KeyboardInsetAnimationCallback#onEnd}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user