1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.chrome.browser.keyboard_accessory; 6 7 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.KeyboardExtensionState.EXTENDING_KEYBOARD; 8 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.KeyboardExtensionState.FLOATING_BAR; 9 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.KeyboardExtensionState.FLOATING_SHEET; 10 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.KeyboardExtensionState.HIDDEN; 11 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.KeyboardExtensionState.REPLACING_KEYBOARD; 12 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.KeyboardExtensionState.WAITING_TO_REPLACE; 13 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.StateProperty.BAR; 14 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.StateProperty.FLOATING; 15 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.StateProperty.HIDDEN_SHEET; 16 import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingProperties.StateProperty.VISIBLE_SHEET; 17 18 import androidx.annotation.IntDef; 19 20 import org.chromium.ui.modelutil.PropertyModel; 21 22 import java.lang.annotation.Retention; 23 import java.lang.annotation.RetentionPolicy; 24 25 /** 26 * Properties defined here reflect the visible state of the ManualFilling-components. 27 */ 28 class ManualFillingProperties { 29 static final PropertyModel.WritableBooleanPropertyKey SHOW_WHEN_VISIBLE = 30 new PropertyModel.WritableBooleanPropertyKey("show_when_visible"); 31 static final PropertyModel.WritableBooleanPropertyKey PORTRAIT_ORIENTATION = 32 new PropertyModel.WritableBooleanPropertyKey("portrait_orientation"); 33 static final PropertyModel.WritableIntPropertyKey KEYBOARD_EXTENSION_STATE = 34 new PropertyModel.WritableIntPropertyKey("keyboard_extension_state"); 35 static final PropertyModel.WritableBooleanPropertyKey SUPPRESSED_BY_BOTTOM_SHEET = 36 new PropertyModel.WritableBooleanPropertyKey("suppressed_by_bottom_sheet"); 37 38 /** 39 * Properties that a given state enforces. Must be between 0x0 and 0x100. 40 * @see KeyboardExtensionState 41 */ 42 @IntDef({BAR, VISIBLE_SHEET, HIDDEN_SHEET}) 43 @Retention(RetentionPolicy.SOURCE) 44 public @interface StateProperty { 45 int BAR = 0x1; // Any state either shows it or hides it - there is no neutral stance. 46 int VISIBLE_SHEET = 0x2; // A state with this property shows the sheet container. 47 int HIDDEN_SHEET = 0x4; // A state with this property hides the sheet container. 48 int FLOATING = 0x8; // A state with this property is not attached to a keyboard. 49 } 50 51 /** 52 * A state is composed of {@link StateProperty}s. A state must ensure the properties are 53 * enforced and the effects are triggered. See more here: 54 * http://go/keyboard-accessory-v2#heading=h.1ack25xnyuxz 55 * 56 * e.g. for <code> int FLOATING_BAR = BAR | HIDDEN_SHEET | FLOATING; </code> 57 * The state FLOATING_BAR must close the sheet but show the bar. To satisfy the FLOATING 58 * property, the state will ensure that the keyboard can not affect it. 59 */ 60 @IntDef({HIDDEN, EXTENDING_KEYBOARD, WAITING_TO_REPLACE, REPLACING_KEYBOARD, FLOATING_BAR, 61 FLOATING_SHEET}) 62 @Retention(RetentionPolicy.SOURCE) 63 public @interface KeyboardExtensionState { 64 int HIDDEN = HIDDEN_SHEET; // == 4 65 int EXTENDING_KEYBOARD = BAR | HIDDEN_SHEET; // == 5 66 int REPLACING_KEYBOARD = BAR | VISIBLE_SHEET; // == 3 67 int WAITING_TO_REPLACE = BAR; // == 1 68 int FLOATING_BAR = BAR | HIDDEN_SHEET | FLOATING; // == 13 69 int FLOATING_SHEET = BAR | VISIBLE_SHEET | FLOATING; // == 11 70 } 71 createFillingModel()72 static PropertyModel createFillingModel() { 73 return new PropertyModel 74 .Builder(SHOW_WHEN_VISIBLE, KEYBOARD_EXTENSION_STATE, PORTRAIT_ORIENTATION, 75 SUPPRESSED_BY_BOTTOM_SHEET) 76 .with(SHOW_WHEN_VISIBLE, false) 77 .with(KEYBOARD_EXTENSION_STATE, HIDDEN) 78 .with(PORTRAIT_ORIENTATION, true) 79 .with(SUPPRESSED_BY_BOTTOM_SHEET, false) 80 .build(); 81 } 82 ManualFillingProperties()83 private ManualFillingProperties() {} 84 } 85