1 /* 2 * Copyright (C) 2021 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 17 package com.android.internal.widget.floatingtoolbar; 18 19 import android.annotation.Nullable; 20 import android.content.Context; 21 import android.graphics.Rect; 22 import android.view.MenuItem; 23 import android.view.View; 24 import android.widget.PopupWindow; 25 26 import java.util.List; 27 28 /** 29 * A popup window used by the {@link FloatingToolbar} to render menu items. 30 * 31 */ 32 public interface FloatingToolbarPopup { 33 34 /** 35 * Sets the suggested dp width of this floating toolbar. 36 * The actual width will be about this size but there are no guarantees that it will be exactly 37 * the suggested width. 38 */ setSuggestedWidth(int suggestedWidth)39 void setSuggestedWidth(int suggestedWidth); 40 41 /** 42 * Sets if the floating toolbar width changed. 43 */ setWidthChanged(boolean widthChanged)44 void setWidthChanged(boolean widthChanged); 45 46 /** 47 * Shows this popup at the specified coordinates. 48 * The specified coordinates may be adjusted to make sure the popup is entirely on-screen. 49 */ show(List<MenuItem> menuItems, MenuItem.OnMenuItemClickListener menuItemClickListener, Rect contentRect)50 void show(List<MenuItem> menuItems, MenuItem.OnMenuItemClickListener menuItemClickListener, 51 Rect contentRect); 52 53 /** 54 * Gets rid of this popup. If the popup isn't currently showing, this will be a no-op. 55 */ dismiss()56 void dismiss(); 57 58 /** 59 * Hides this popup. This is a no-op if this popup is not showing. 60 * Use {@link #isHidden()} to distinguish between a hidden and a dismissed popup. 61 */ hide()62 void hide(); 63 64 /** 65 * Returns {@code true} if this popup is currently showing. {@code false} otherwise. 66 */ isShowing()67 boolean isShowing(); 68 69 /** 70 * Returns {@code true} if this popup is currently hidden. {@code false} otherwise. 71 */ isHidden()72 boolean isHidden(); 73 74 /** 75 * Makes this toolbar "outside touchable" and sets the onDismissListener. 76 * 77 * @param outsideTouchable if true, the popup will be made "outside touchable" and 78 * "non focusable". The reverse will happen if false. 79 * @param onDismiss 80 * 81 * @return true if the "outsideTouchable" setting was modified. Otherwise returns false 82 * 83 * @see PopupWindow#setOutsideTouchable(boolean) 84 * @see PopupWindow#setFocusable(boolean) 85 * @see PopupWindow.OnDismissListener 86 */ setOutsideTouchable(boolean outsideTouchable, @Nullable PopupWindow.OnDismissListener onDismiss)87 boolean setOutsideTouchable(boolean outsideTouchable, 88 @Nullable PopupWindow.OnDismissListener onDismiss); 89 90 /** 91 * Returns {@link LocalFloatingToolbarPopup} implementation. 92 */ createInstance(Context context, View parent)93 static FloatingToolbarPopup createInstance(Context context, View parent) { 94 return new LocalFloatingToolbarPopup(context, parent); 95 } 96 97 } 98