1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.launcher3.logging; 17 18 import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.NO_IME_ACTION; 19 20 import android.os.SystemClock; 21 22 /** 23 * Class to maintain keyboard states. 24 */ 25 public class KeyboardStateManager { 26 private long mUpdatedTime; 27 private int mImeHeightPx; 28 // Height of the keyboard when it's shown. 29 // mImeShownHeightPx>=mImeHeightPx always. 30 private int mImeShownHeightPx; 31 // Indicate if the latest All Apps session was started from a11y action (rather than a direct 32 // user interaction). 33 private boolean mLaunchedFromA11y; 34 35 public enum KeyboardState { 36 NO_IME_ACTION, 37 SHOW, 38 HIDE, 39 } 40 41 private KeyboardState mKeyboardState; 42 KeyboardStateManager(int defaultImeShownHeightPx)43 public KeyboardStateManager(int defaultImeShownHeightPx) { 44 mKeyboardState = NO_IME_ACTION; 45 mImeShownHeightPx = defaultImeShownHeightPx; 46 } 47 48 /** 49 * Returns time when keyboard state was updated. 50 */ getLastUpdatedTime()51 public long getLastUpdatedTime() { 52 return mUpdatedTime; 53 } 54 55 /** 56 * Returns current keyboard state. 57 */ getKeyboardState()58 public KeyboardState getKeyboardState() { 59 return mKeyboardState; 60 } 61 62 /** 63 * Setter method to set keyboard state. 64 */ setKeyboardState(KeyboardState keyboardState)65 public void setKeyboardState(KeyboardState keyboardState) { 66 mUpdatedTime = SystemClock.elapsedRealtime(); 67 mKeyboardState = keyboardState; 68 } 69 70 /** 71 * Returns keyboard's current height. 72 */ getImeHeight()73 public int getImeHeight() { 74 return mImeHeightPx; 75 } 76 77 /** 78 * Returns keyboard's height in pixels when shown. 79 */ getImeShownHeight()80 public int getImeShownHeight() { 81 return mImeShownHeightPx; 82 } 83 84 /** 85 * Setter method to set keyboard height in pixels. 86 */ setImeHeight(int imeHeightPx)87 public void setImeHeight(int imeHeightPx) { 88 mImeHeightPx = imeHeightPx; 89 if (mImeHeightPx > 0) { 90 // Update the mImeShownHeightPx with the actual ime height when shown and store it 91 // for future sessions. 92 mImeShownHeightPx = mImeHeightPx; 93 } 94 } 95 96 /** Getter for {@code mLaunchedFromA11y} */ getLaunchedFromA11y()97 public boolean getLaunchedFromA11y() { 98 return mLaunchedFromA11y; 99 } 100 101 /** Setter for {@code mLaunchedFromA11y} */ setLaunchedFromA11y(boolean fromA11y)102 public void setLaunchedFromA11y(boolean fromA11y) { 103 mLaunchedFromA11y = fromA11y; 104 } 105 } 106